Compare commits

20 Commits

Author SHA1 Message Date
5faffde48b Merge pull request 'build: Remove typo' (#3) from fix-release-pipeline into main
Some checks failed
Release packages / build-and-release-artifact (push) Failing after 1m36s
Reviewed-on: #3
2025-07-03 23:57:20 +02:00
96afdc76c2 build: Remove typo
All checks were successful
Code style / cargo-fmt (pull_request) Successful in 1m34s
Code style / cargo-check (pull_request) Successful in 1m33s
Code style / clippy (pull_request) Successful in 1m33s
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:56:57 +02:00
c2df03303b Merge pull request 'feat(setup-repo): Use URI to generate target directory if not provided' (#2) from optional-target-dir into main
Some checks failed
Release packages / build-and-release-artifact (push) Failing after 0s
Reviewed-on: #2
2025-07-03 23:53:23 +02:00
5d745678f3 chore: Fix formatting
All checks were successful
Code style / cargo-fmt (pull_request) Successful in 1m20s
Code style / cargo-check (pull_request) Successful in 1m14s
Code style / clippy (pull_request) Successful in 1m13s
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:43:13 +02:00
cf5b30015a build: Update release pipeline
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:40:41 +02:00
476f849ded build: Update the linting workflow
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:37:27 +02:00
8c22757f71 chore(create-worktree): Update git lib version to 0.2.0
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:16:39 +02:00
0793c8bbd7 chore(setup-repo): Update the git lib version to 0.2.0
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:16:11 +02:00
ddad92dc32 chore(setup-repo): Fix clippy warnings
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:15:49 +02:00
002c85329e feat(git): Remove the failure code from the error type
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 23:15:19 +02:00
b46621f772 chore(setup-repo): Bump version to 0.2.0
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 22:58:37 +02:00
c0fe91f916 feat(setup-repo): Use the last part of the URI as directory if none is provided
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 22:57:41 +02:00
446a3a2f3f Each entry on their own line
Signed-off-by: Noah Knegt <git@noahknegt.com>
2025-07-03 22:34:44 +02:00
Noah Knegt
69f94c64b6 Create libs for common code
Update libs
2025-05-08 16:50:03 +02:00
5d372f87cb Use token in publish
Some checks failed
Release packages / build-and-release-artifact (push) Failing after 1m13s
2025-05-07 21:08:04 +02:00
cf2722feee Update token
Some checks failed
Release packages / build-and-release-artifact (push) Failing after 1m11s
2025-05-07 21:03:17 +02:00
42c87cf6e5 Update config file 2025-05-07 20:11:07 +02:00
39904c22c1 Update cargo configurations
Some checks failed
Release packages / build-and-release-artifact (push) Failing after 1m19s
2025-05-07 20:03:31 +02:00
9594c3b5aa Workflows 2025-05-07 19:46:16 +02:00
8e44310c41 Add cargo lock file 2025-05-07 19:25:38 +02:00
16 changed files with 1000 additions and 264 deletions

View File

@@ -0,0 +1,80 @@
name: Code style
on:
workflow_dispatch:
pull_request:
env:
CARGO_TERM_COLOR: always
jobs:
cargo-fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
# Cache cargo registry
- name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1
id: get-hash
with:
patterns: |
**/Cargo.lock
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt,clippy
cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
cargo-check:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
# Cache cargo registry
- name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1
id: get-hash
with:
patterns: |
**/Cargo.lock
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt,clippy
cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
- name: Cargo check
run: cargo check --workspace
clippy:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
# Cache cargo registry
- name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1
id: get-hash
with:
patterns: |
**/Cargo.lock
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt,clippy
cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
- name: Cargo check
run: cargo clippy --all-targets --all-features -- -Dwarnings

View File

@@ -0,0 +1,47 @@
---
name: Release packages
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
build-and-release-artifact:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Cache cargo registry
- name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1
id: get-hash
with:
patterns: |
**/Cargo.lock
- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
matcher: false
- name: Build application
run: cargo build --release --all-features --workspace --all-targets
- name: Package application
run: cargo package --all-features --workspace --allow-dirty
- name: Add registry to cargo config
run: echo -e '[registries.gitea]\nindex = "sparse+https://git.noahknegt.com/api/packages/${{ github.repository_owner }}/cargo/"\n' > ~/.cargo/config.toml
- name: Publish to cargo registry
run: cargo publish --no-verify --registry gitea --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_NET_RETRY: 2
CARGO_NET_TIMEOUT: 120

541
Cargo.lock generated Normal file
View File

@@ -0,0 +1,541 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]]
name = "bumpalo"
version = "3.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "colored"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
dependencies = [
"windows-sys",
]
[[package]]
name = "command-with-spinner"
version = "0.1.0"
dependencies = [
"anyhow",
"colored",
"indicatif",
"thiserror",
]
[[package]]
name = "console"
version = "0.15.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
dependencies = [
"encode_unicode",
"libc",
"once_cell",
"unicode-width",
"windows-sys",
]
[[package]]
name = "create-worktree"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"colored",
"dirs",
"git",
"indicatif",
"thiserror",
]
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys",
]
[[package]]
name = "encode_unicode"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "getrandom"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "git"
version = "0.2.0"
dependencies = [
"anyhow",
"command-with-spinner",
"thiserror",
]
[[package]]
name = "git-ssh-bitwarden"
version = "0.1.0"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "indicatif"
version = "0.17.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
dependencies = [
"console",
"number_prefix",
"portable-atomic",
"unicode-width",
"web-time",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "js-sys"
version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags",
"libc",
]
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "portable-atomic"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_users"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]]
name = "setup-repo"
version = "0.2.0"
dependencies = [
"anyhow",
"clap",
"colored",
"git",
"indicatif",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
"once_cell",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]
[[package]]
name = "web-time"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

View File

@@ -1,6 +1,16 @@
[workspace] [workspace]
resolver = "3" resolver = "3"
members = [ members = [
"create-worktree", "command-with-spinner",
"create-worktree",
"git",
"git-ssh-bitwarden",
"setup-repo", "setup-repo",
] ]
package.edition = "2024"
package.authors = [
"Noah Knegt <personal@noahknegt.com>"
]
package.license-file = "LICENSE"
package.repository = "https://git.noahknegt.com/noah.knegt/repo-utils"

View File

@@ -0,0 +1,14 @@
[package]
name = "command-with-spinner"
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license-file.workspace = true
repository.workspace = true
[dependencies]
anyhow = "1.0.98"
colored = "3.0.0"
indicatif = "0.17.11"
thiserror = "2.0"

View File

@@ -0,0 +1,12 @@
/// Git operations error type
#[derive(Debug, thiserror::Error)]
pub enum CommandError {
#[error("Command failed with exit code: {0}")]
Failed(i32),
#[error("Command failed without exit code")]
FailedNoCode,
#[error("Failed to execute command: {0}")]
ExecutionError(#[from] std::io::Error),
}

View File

@@ -0,0 +1,42 @@
use std::process::{Command, Stdio};
use anyhow::{Context, Result};
use colored::*;
use indicatif::{ProgressBar, ProgressStyle};
mod error;
use error::CommandError;
/// Runs a git command with a progress spinner
pub fn run_command(command: &mut Command, message: &str) -> Result<()> {
let spinner = ProgressBar::new_spinner();
spinner.set_style(
ProgressStyle::default_spinner()
.tick_chars("⣾⣽⣻⢿⡿⣟⣯⣷")
.template("{spinner:.green} {msg}")
.expect("Invalid template format"),
);
spinner.set_message(message.to_string());
// Configure the command to not show output
command.stdout(Stdio::null()).stderr(Stdio::null());
// Execute the command and wait for it to complete
spinner.enable_steady_tick(std::time::Duration::from_millis(100));
let status = command.status().context("Failed to execute command")?;
spinner.finish_and_clear();
if status.success() {
println!("{message} {}", "Done.".green());
Ok(())
} else {
println!("{message} {}", "FAILED.".red());
let code = status.code();
match code {
Some(code) => Err(CommandError::Failed(code).into()),
None => Err(CommandError::FailedNoCode.into()),
}
}
}

View File

@@ -1,14 +1,18 @@
[package] [package]
name = "create-worktree" name = "create-worktree"
version = "0.1.0" version = "0.1.0"
edition = "2024"
authors = ["Noah Knegt <noah.knegt@priva.com>"]
description = "A tool to create git worktrees with convenient branch management" description = "A tool to create git worktrees with convenient branch management"
edition.workspace = true
authors.workspace = true
license-file.workspace = true
repository.workspace = true
[dependencies] [dependencies]
clap = { version = "4.5", features = ["derive"] }
anyhow = "1.0" anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] }
colored = "3.0" colored = "3.0"
indicatif = "0.17"
dirs = "6.0" dirs = "6.0"
git = { version = "0.2.0", path = "../git" }
indicatif = "0.17"
thiserror = { version = "2.0" } thiserror = { version = "2.0" }

View File

@@ -1,11 +1,11 @@
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::process::{Command, Stdio};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::{ArgAction, Parser}; use clap::{ArgAction, Parser};
use colored::*; use colored::*;
use indicatif::{ProgressBar, ProgressStyle};
use git::Git;
/// Tool to create git worktrees with convenient branch management /// Tool to create git worktrees with convenient branch management
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@@ -39,133 +39,6 @@ struct Args {
no_color: bool, no_color: bool,
} }
/// Git operations error type
#[derive(Debug, thiserror::Error)]
enum GitError {
#[error("Command failed with exit code: {0}")]
Failed(i32),
#[error("Command failed without exit code")]
FailedNoCode,
#[error("Failed to execute command: {0}")]
ExecutionError(#[from] std::io::Error),
}
/// Runs a git command with a progress spinner
fn run_command(command: &mut Command, message: &str) -> Result<()> {
let spinner = ProgressBar::new_spinner();
spinner.set_style(
ProgressStyle::default_spinner()
.tick_chars("⣾⣽⣻⢿⡿⣟⣯⣷")
.template("{spinner:.green} {msg}")
.expect("Invalid template format"),
);
spinner.set_message(message.to_string());
// Configure the command to not show output
command.stdout(Stdio::null()).stderr(Stdio::null());
// Execute the command and wait for it to complete
spinner.enable_steady_tick(std::time::Duration::from_millis(100));
let status = command.status().context("Failed to execute command")?;
spinner.finish_and_clear();
if status.success() {
println!("{message} {}", "Done.".green());
Ok(())
} else {
println!("{message} {}", "FAILED.".red());
let code = status.code();
match code {
Some(code) => Err(GitError::Failed(code).into()),
None => Err(GitError::FailedNoCode.into()),
}
}
}
/// Git command wrapper
struct Git;
impl Git {
/// Check if a branch exists locally
fn branch_exists_locally(branch: &str) -> Result<bool> {
let output = Command::new("git")
.args([
"branch",
"--list",
branch
])
.output()
.context("Failed to check branch existence")?;
Ok(!output.stdout.is_empty())
}
/// Check if a branch exists on the remote
fn branch_exists_on_remote(branch: &str) -> Result<bool> {
let output = Command::new("git")
.args([
"ls-remote",
"--heads",
"origin",
branch
])
.output()
.context("Failed to check remote branch existence")?;
Ok(!output.stdout.is_empty())
}
/// Create a new worktree with an existing branch
fn create_worktree_existing_branch(worktree_path: &str, branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args([
"worktree",
"add",
worktree_path,
branch
]);
run_command(&mut cmd, &format!("Generating new worktree from existing branch: {branch}"))
}
/// Create a new worktree with a new branch
fn create_worktree_new_branch(worktree_path: &str, branch: &str, base: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args([
"worktree",
"add",
"-b", branch,
worktree_path,
base
]);
run_command(&mut cmd, &format!("Generating new worktree: {worktree_path}"))
}
/// Create and push a new remote branch
fn create_remote_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args([
"push",
"-u", "origin",
branch
]);
run_command(&mut cmd, &format!("Creating remote branch {branch}..."))
}
/// Set the upstream branch
fn set_upstream_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args([
"branch",
"--set-upstream-to", &format!("origin/{branch}")
]);
run_command(&mut cmd, &format!("Setting upstream branch to 'origin/{branch}'"))
}
}
/// Update or create the remote tracking branch /// Update or create the remote tracking branch
fn update_remote(branch: &str, create_upstream: bool) -> Result<()> { fn update_remote(branch: &str, create_upstream: bool) -> Result<()> {
// Do nothing if create_upstream is disabled // Do nothing if create_upstream is disabled
@@ -178,11 +51,17 @@ fn update_remote(branch: &str, create_upstream: bool) -> Result<()> {
if !has_remote { if !has_remote {
// Create remote branch // Create remote branch
println!("{}", format!("Branch '{branch}' does not exist on remote. Creating.").dimmed()); println!(
"{}",
format!("Branch '{branch}' does not exist on remote. Creating.").dimmed()
);
Git::set_upstream_branch(branch)?; Git::set_upstream_branch(branch)?;
// Git::create_remote_branch(branch)?; // Git::create_remote_branch(branch)?;
} else { } else {
println!("{}", format!("Branch '{branch}' exists. Setting upstream.").dimmed()); println!(
"{}",
format!("Branch '{branch}' exists. Setting upstream.").dimmed()
);
Git::set_upstream_branch(branch)?; Git::set_upstream_branch(branch)?;
} }
@@ -200,11 +79,16 @@ fn main() -> Result<()> {
if args.verbose { if args.verbose {
println!("{}", "Verbose mode enabled".dimmed()); println!("{}", "Verbose mode enabled".dimmed());
println!("{}", format!("Base branch: {}", args.base).dimmed()); println!("{}", format!("Base branch: {}", args.base).dimmed());
println!("{}", format!("Create upstream: {}", args.no_create_upstream).dimmed()); println!(
"{}",
format!("Create upstream: {}", args.no_create_upstream).dimmed()
);
} }
// Determine branch name if not specified // Determine branch name if not specified
let branch = args.branch.unwrap_or_else(|| format!("{}{}", args.prefix, args.worktree)); let branch = args
.branch
.unwrap_or_else(|| format!("{}{}", args.prefix, args.worktree));
// Normalize paths // Normalize paths
let worktree_path = Path::new(&args.worktree).to_string_lossy(); let worktree_path = Path::new(&args.worktree).to_string_lossy();
@@ -220,7 +104,10 @@ fn main() -> Result<()> {
} }
// Change to worktree directory // Change to worktree directory
println!("{}", format!("Moving into worktree: {worktree_path}").dimmed()); println!(
"{}",
format!("Moving into worktree: {worktree_path}").dimmed()
);
env::set_current_dir(&args.worktree).context("Failed to change directory")?; env::set_current_dir(&args.worktree).context("Failed to change directory")?;
// Update remote // Update remote

View File

@@ -0,0 +1,10 @@
[package]
name = "git-ssh-bitwarden"
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license-file.workspace = true
repository.workspace = true
[dependencies]

View File

@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

13
git/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "git"
version = "0.2.0"
edition.workspace = true
authors.workspace = true
license-file.workspace = true
repository.workspace = true
[dependencies]
anyhow = "1.0.98"
command-with-spinner = { version = "0.1.0", path = "../command-with-spinner" }
thiserror = "2.0"

9
git/src/error.rs Normal file
View File

@@ -0,0 +1,9 @@
/// Git operations error type
#[derive(Debug, thiserror::Error)]
pub enum GitError {
#[error("Command failed without exit code")]
FailedNoCode,
#[error("Failed to execute command: {0}")]
ExecutionError(#[from] std::io::Error),
}

148
git/src/lib.rs Normal file
View File

@@ -0,0 +1,148 @@
use std::{path::Path, process::Command};
use anyhow::{Context, Result};
use command_with_spinner::run_command;
use error::GitError;
mod error;
/// Git command wrapper
pub struct Git;
impl Git {
/// Clone a repository as a bare clone in a .bare directory
pub fn clone_bare_repo(repo_url: &str, target_dir: &str) -> Result<()> {
// Create the base directory first
std::fs::create_dir_all(target_dir).context("Failed to create target directory")?;
// Create the .bare subdirectory path
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
// Clone the repository as a bare clone into .bare directory
let mut cmd = Command::new("git");
cmd.args(["clone", "--bare", repo_url, &bare_dir_str]);
match run_command(
&mut cmd,
&format!("Cloning repository as bare clone into {bare_dir_str}"),
) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Set up the .git file to point to the .bare directory
pub fn setup_git_pointer(target_dir: &str) -> Result<()> {
let git_file_path = Path::new(target_dir).join(".git");
std::fs::write(git_file_path, "gitdir: ./.bare")
.context("Failed to create .git file pointing to .bare directory")
}
/// Configure remote.origin.fetch to fetch all references
pub fn configure_remote_fetch(target_dir: &str) -> Result<()> {
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
let mut cmd = Command::new("git");
cmd.args([
"--git-dir",
&bare_dir_str,
"config",
"remote.origin.fetch",
"+refs/heads/*:refs/remotes/origin/*",
]);
match run_command(&mut cmd, "Configuring remote.origin.fetch") {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Fetch all remotes
pub fn fetch_remotes(target_dir: &str) -> Result<()> {
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
let mut cmd = Command::new("git");
cmd.args(["--git-dir", &bare_dir_str, "fetch", "--all"]);
match run_command(&mut cmd, "Fetching all remotes") {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Check if a branch exists locally
pub fn branch_exists_locally(branch: &str) -> Result<bool> {
let output = Command::new("git")
.args(["branch", "--list", branch])
.output()
.context("Failed to check branch existence")?;
Ok(!output.stdout.is_empty())
}
/// Check if a branch exists on the remote
pub fn branch_exists_on_remote(branch: &str) -> Result<bool> {
let output = Command::new("git")
.args(["ls-remote", "--heads", "origin", branch])
.output()
.context("Failed to check remote branch existence")?;
Ok(!output.stdout.is_empty())
}
/// Create a new worktree with an existing branch
pub fn create_worktree_existing_branch(worktree_path: &str, branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args(["worktree", "add", worktree_path, branch]);
match run_command(
&mut cmd,
&format!("Generating new worktree from existing branch: {branch}"),
) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Create a new worktree with a new branch
pub fn create_worktree_new_branch(worktree_path: &str, branch: &str, base: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args(["worktree", "add", "-b", branch, worktree_path, base]);
match run_command(
&mut cmd,
&format!("Generating new worktree: {worktree_path}"),
) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Create and push a new remote branch
pub fn create_remote_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args(["push", "-u", "origin", branch]);
match run_command(&mut cmd, &format!("Creating remote branch {branch}...")) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
/// Set the upstream branch
pub fn set_upstream_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git");
cmd.args(["branch", "--set-upstream-to", &format!("origin/{branch}")]);
match run_command(
&mut cmd,
&format!("Setting upstream branch to 'origin/{branch}'"),
) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
}

View File

@@ -1,13 +1,16 @@
[package] [package]
name = "setup-repo" name = "setup-repo"
version = "0.1.0" version = "0.2.0"
edition = "2024"
description = "Tool to set up Git repositories for worktree development" description = "Tool to set up Git repositories for worktree development"
authors = ["Noah Knegt <noah.knegt@priva.com>"]
edition.workspace = true
authors.workspace = true
license-file.workspace = true
repository.workspace = true
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
colored = "3.0" colored = "3.0"
git = { version = "0.2.0", path = "../git" }
indicatif = "0.17" indicatif = "0.17"
thiserror = "2.0"

View File

@@ -1,10 +1,8 @@
use std::path::Path; use anyhow::Result;
use std::process::{Command, Stdio};
use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
use colored::*; use colored::*;
use indicatif::{ProgressBar, ProgressStyle};
use git::Git;
/// Tool to set up Git repositories for worktree development /// Tool to set up Git repositories for worktree development
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@@ -16,7 +14,7 @@ struct Args {
/// Target directory for the repository setup /// Target directory for the repository setup
#[arg(short, long)] #[arg(short, long)]
target_dir: String, target_dir: Option<String>,
/// Enable verbose output /// Enable verbose output
#[arg(short, long)] #[arg(short, long)]
@@ -27,113 +25,6 @@ struct Args {
no_color: bool, no_color: bool,
} }
/// Git operations error type
#[derive(Debug, thiserror::Error)]
enum GitError {
#[error("Command failed with exit code: {0}")]
Failed(i32),
#[error("Command failed without exit code")]
FailedNoCode,
#[error("Failed to execute command: {0}")]
ExecutionError(#[from] std::io::Error),
}
/// Runs a command with a progress spinner
fn run_command(command: &mut Command, message: &str) -> Result<()> {
let spinner = ProgressBar::new_spinner();
spinner.set_style(
ProgressStyle::default_spinner()
.tick_chars("⣾⣽⣻⢿⡿⣟⣯⣷")
.template("{spinner:.green} {msg}")
.expect("Invalid template format"),
);
spinner.set_message(message.to_string());
// Configure the command to not show output
command.stdout(Stdio::null()).stderr(Stdio::null());
// Execute the command and wait for it to complete
spinner.enable_steady_tick(std::time::Duration::from_millis(100));
let status = command.status().context("Failed to execute command")?;
spinner.finish_and_clear();
if status.success() {
println!("{message} {}", "Done.".green());
Ok(())
} else {
println!("{message} {}", "FAILED.".red());
let code = status.code();
match code {
Some(code) => Err(GitError::Failed(code).into()),
None => Err(GitError::FailedNoCode.into()),
}
}
}
/// Git command wrapper
struct Git;
impl Git {
/// Clone a repository as a bare clone in a .bare directory
fn clone_bare_repo(repo_url: &str, target_dir: &str) -> Result<()> {
// Create the base directory first
std::fs::create_dir_all(target_dir).context("Failed to create target directory")?;
// Create the .bare subdirectory path
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
// Clone the repository as a bare clone into .bare directory
let mut cmd = Command::new("git");
cmd.args([
"clone",
"--bare",
repo_url,
&bare_dir_str
]);
run_command(&mut cmd, &format!("Cloning repository as bare clone into {bare_dir_str}"))
}
/// Set up the .git file to point to the .bare directory
fn setup_git_pointer(target_dir: &str) -> Result<()> {
let git_file_path = Path::new(target_dir).join(".git");
std::fs::write(git_file_path, "gitdir: ./.bare")
.context("Failed to create .git file pointing to .bare directory")
}
/// Configure remote.origin.fetch to fetch all references
fn configure_remote_fetch(target_dir: &str) -> Result<()> {
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
let mut cmd = Command::new("git");
cmd.args([
"--git-dir", &bare_dir_str,
"config",
"remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
]);
run_command(&mut cmd, "Configuring remote.origin.fetch")
}
/// Fetch all remotes
fn fetch_remotes(target_dir: &str) -> Result<()> {
let bare_dir = Path::new(target_dir).join(".bare");
let bare_dir_str = bare_dir.to_string_lossy();
let mut cmd = Command::new("git");
cmd.args([
"--git-dir", &bare_dir_str,
"fetch",
"--all"
]);
run_command(&mut cmd, "Fetching all remotes")
}
}
fn main() -> Result<()> { fn main() -> Result<()> {
// Parse arguments // Parse arguments
let args = Args::parse(); let args = Args::parse();
@@ -141,28 +32,50 @@ fn main() -> Result<()> {
// Enable or disable colored output // Enable or disable colored output
colored::control::set_override(!args.no_color); colored::control::set_override(!args.no_color);
let target_dir = match args.target_dir {
Some(dir) => dir,
// If a directory is not provided construct one from the last part of the URI.
// This behavior follows git itself
None => {
let start = args.repo_url.rfind("/").unwrap() + 1;
let end = match args.repo_url.rfind(".git") {
Some(index) => index,
None => args.repo_url.len(),
};
args.repo_url[start..end].to_owned()
}
};
// Print verbose information if enabled // Print verbose information if enabled
if args.verbose { if args.verbose {
println!("{}", "Verbose mode enabled".dimmed()); println!("{}", "Verbose mode enabled".dimmed());
println!("{}", format!("Repository URL: {}", args.repo_url).dimmed()); println!("{}", format!("Repository URL: {}", args.repo_url).dimmed());
println!("{}", format!("Target directory: {}", args.target_dir).dimmed()); println!("{}", format!("Target directory: {target_dir}").dimmed());
} }
println!("{}", "Setting up repository for worktree development".blue()); println!(
"{}",
"Setting up repository for worktree development".blue()
);
// Clone the repository as a bare clone // Clone the repository as a bare clone
Git::clone_bare_repo(&args.repo_url, &args.target_dir)?; Git::clone_bare_repo(&args.repo_url, &target_dir)?;
// Set up the .git file to point to the .bare directory // Set up the .git file to point to the .bare directory
Git::setup_git_pointer(&args.target_dir)?; Git::setup_git_pointer(&target_dir)?;
// Configure the remote.origin.fetch setting // Configure the remote.origin.fetch setting
Git::configure_remote_fetch(&args.target_dir)?; Git::configure_remote_fetch(&target_dir)?;
// Fetch all remotes // Fetch all remotes
Git::fetch_remotes(&args.target_dir)?; Git::fetch_remotes(&target_dir)?;
println!("{}", "Repository setup complete.".green()); println!("{}", "Repository setup complete.".green());
println!("{}", format!("You can now create worktrees in '{}'.", args.target_dir).green()); println!(
"{}",
format!("You can now create worktrees in '{target_dir}'.").green()
);
Ok(()) Ok(())
} }