Compare commits

...

11 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
10 changed files with 138 additions and 170 deletions

View File

@@ -7,18 +7,12 @@ env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
jobs: jobs:
cargo-check: cargo-fmt:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt,clippy
# Cache cargo registry # Cache cargo registry
- name: Hash the lock file - name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1 uses: https://gitea.com/seepine/hash-files@v1
@@ -26,24 +20,40 @@ jobs:
with: with:
patterns: | patterns: |
**/Cargo.lock **/Cargo.lock
- name: Cache cargo registry
uses: actions/cache@v3 - name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
path: | toolchain: stable
~/.cargo/bin/ components: rustfmt,clippy
~/.cargo/registry/index/ cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
~/.cargo/registry/cache/
~/.cargo/git/db/ - name: Rustfmt Check
target/ uses: actions-rust-lang/rustfmt@v1
key: cargo-${{ steps.get-hash.outputs.hash }}
restore-keys: | cargo-check:
cargo- runs-on: ubuntu-latest
# Cache cargo registry - end 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 - name: Cargo check
uses: actions-rs/cargo@v1 run: cargo check --workspace
with:
command: check
clippy: clippy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -51,12 +61,6 @@ jobs:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt,clippy
# Cache cargo registry # Cache cargo registry
- name: Hash the lock file - name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1 uses: https://gitea.com/seepine/hash-files@v1
@@ -64,22 +68,13 @@ jobs:
with: with:
patterns: | patterns: |
**/Cargo.lock **/Cargo.lock
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ steps.get-hash.outputs.hash }}
restore-keys: |
cargo-
# Cache cargo registry - end
- name: Run clippy - name: Setup rust
uses: actions-rs/clippy-check@v1 uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} toolchain: stable
args: --all-targets --all-features -- -Dwarnings 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

@@ -15,12 +15,6 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
# Cache cargo registry # Cache cargo registry
- name: Hash the lock file - name: Hash the lock file
uses: https://gitea.com/seepine/hash-files@v1 uses: https://gitea.com/seepine/hash-files@v1
@@ -28,40 +22,25 @@ jobs:
with: with:
patterns: | patterns: |
**/Cargo.lock **/Cargo.lock
- name: Cache cargo registry
uses: actions/cache@v4 - name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
path: | toolchain: stable
~/.cargo/bin/ cache-shared-key: cargo-${{ steps.get-hash.outputs.hash }}
~/.cargo/registry/index/ matcher: false
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: cargo-${{ steps.get-hash.outputs.hash }}
restore-keys: |
cargo-
# Cache cargo registry - end
- name: Build application - name: Build application
uses: actions-rs/cargo@v1 run: cargo build --release --all-features --workspace --all-targets
with:
command: build
args: --release --all-features --workspace --all-targets
- name: Package application - name: Package application
uses: actions-rs/cargo@v1 run: cargo package --all-features --workspace --allow-dirty
with:
command: package
args: --all-features --workspace --allow-dirty
- name: Add registry to cargo config - 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 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 - name: Publish to cargo registry
uses: actions-rs/cargo@v1 run: cargo publish --no-verify --registry gitea --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
with:
command: publish
args: --no-verify --registry gitea --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env: env:
CARGO_NET_GIT_FETCH_WITH_CLI: true CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_NET_RETRY: 2 CARGO_NET_RETRY: 2

4
Cargo.lock generated
View File

@@ -207,7 +207,7 @@ dependencies = [
[[package]] [[package]]
name = "git" name = "git"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"command-with-spinner", "command-with-spinner",
@@ -330,7 +330,7 @@ dependencies = [
[[package]] [[package]]
name = "setup-repo" name = "setup-repo"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View File

@@ -13,6 +13,6 @@ anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
colored = "3.0" colored = "3.0"
dirs = "6.0" dirs = "6.0"
git = { version = "0.1.0", path = "../git" } git = { version = "0.2.0", path = "../git" }
indicatif = "0.17" indicatif = "0.17"
thiserror = { version = "2.0" } thiserror = { version = "2.0" }

View File

@@ -51,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)?;
} }
@@ -73,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();
@@ -93,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

@@ -1,6 +1,6 @@
[package] [package]
name = "git" name = "git"
version = "0.1.0" version = "0.2.0"
edition.workspace = true edition.workspace = true
authors.workspace = true authors.workspace = true

View File

@@ -1,9 +1,6 @@
/// Git operations error type /// Git operations error type
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum GitError { pub enum GitError {
#[error("Command failed with exit code: {0}")]
Failed(i32),
#[error("Command failed without exit code")] #[error("Command failed without exit code")]
FailedNoCode, FailedNoCode,

View File

@@ -21,16 +21,14 @@ impl Git {
// Clone the repository as a bare clone into .bare directory // Clone the repository as a bare clone into .bare directory
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["clone", "--bare", repo_url, &bare_dir_str]);
"clone",
"--bare",
repo_url,
&bare_dir_str
]);
match run_command(&mut cmd, &format!("Cloning repository as bare clone into {bare_dir_str}")) { match run_command(
&mut cmd,
&format!("Cloning repository as bare clone into {bare_dir_str}"),
) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
@@ -48,14 +46,16 @@ impl Git {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args([
"--git-dir", &bare_dir_str, "--git-dir",
&bare_dir_str,
"config", "config",
"remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" "remote.origin.fetch",
"+refs/heads/*:refs/remotes/origin/*",
]); ]);
match run_command(&mut cmd, "Configuring remote.origin.fetch") { match run_command(&mut cmd, "Configuring remote.origin.fetch") {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
@@ -65,26 +65,18 @@ impl Git {
let bare_dir_str = bare_dir.to_string_lossy(); let bare_dir_str = bare_dir.to_string_lossy();
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["--git-dir", &bare_dir_str, "fetch", "--all"]);
"--git-dir", &bare_dir_str,
"fetch",
"--all"
]);
match run_command(&mut cmd, "Fetching all remotes") { match run_command(&mut cmd, "Fetching all remotes") {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
/// Check if a branch exists locally /// Check if a branch exists locally
pub fn branch_exists_locally(branch: &str) -> Result<bool> { pub fn branch_exists_locally(branch: &str) -> Result<bool> {
let output = Command::new("git") let output = Command::new("git")
.args([ .args(["branch", "--list", branch])
"branch",
"--list",
branch
])
.output() .output()
.context("Failed to check branch existence")?; .context("Failed to check branch existence")?;
@@ -94,12 +86,7 @@ impl Git {
/// Check if a branch exists on the remote /// Check if a branch exists on the remote
pub fn branch_exists_on_remote(branch: &str) -> Result<bool> { pub fn branch_exists_on_remote(branch: &str) -> Result<bool> {
let output = Command::new("git") let output = Command::new("git")
.args([ .args(["ls-remote", "--heads", "origin", branch])
"ls-remote",
"--heads",
"origin",
branch
])
.output() .output()
.context("Failed to check remote branch existence")?; .context("Failed to check remote branch existence")?;
@@ -109,62 +96,53 @@ impl Git {
/// Create a new worktree with an existing branch /// Create a new worktree with an existing branch
pub fn create_worktree_existing_branch(worktree_path: &str, branch: &str) -> Result<()> { pub fn create_worktree_existing_branch(worktree_path: &str, branch: &str) -> Result<()> {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["worktree", "add", worktree_path, branch]);
"worktree",
"add",
worktree_path,
branch
]);
match run_command(&mut cmd, &format!("Generating new worktree from existing branch: {branch}")) { match run_command(
&mut cmd,
&format!("Generating new worktree from existing branch: {branch}"),
) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
/// Create a new worktree with a new branch /// Create a new worktree with a new branch
pub fn create_worktree_new_branch(worktree_path: &str, branch: &str, base: &str) -> Result<()> { pub fn create_worktree_new_branch(worktree_path: &str, branch: &str, base: &str) -> Result<()> {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["worktree", "add", "-b", branch, worktree_path, base]);
"worktree",
"add",
"-b", branch,
worktree_path,
base
]);
match run_command(&mut cmd, &format!("Generating new worktree: {worktree_path}")) { match run_command(
&mut cmd,
&format!("Generating new worktree: {worktree_path}"),
) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
/// Create and push a new remote branch /// Create and push a new remote branch
pub fn create_remote_branch(branch: &str) -> Result<()> { pub fn create_remote_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["push", "-u", "origin", branch]);
"push",
"-u", "origin",
branch
]);
match run_command(&mut cmd, &format!("Creating remote branch {branch}...")) { match run_command(&mut cmd, &format!("Creating remote branch {branch}...")) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
/// Set the upstream branch /// Set the upstream branch
pub fn set_upstream_branch(branch: &str) -> Result<()> { pub fn set_upstream_branch(branch: &str) -> Result<()> {
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.args([ cmd.args(["branch", "--set-upstream-to", &format!("origin/{branch}")]);
"branch",
"--set-upstream-to", &format!("origin/{branch}")
]);
match run_command(&mut cmd, &format!("Setting upstream branch to 'origin/{branch}'")) { match run_command(
&mut cmd,
&format!("Setting upstream branch to 'origin/{branch}'"),
) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into()) Err(_) => Err(GitError::FailedNoCode.into()),
} }
} }
} }

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "setup-repo" name = "setup-repo"
version = "0.1.0" version = "0.2.0"
description = "Tool to set up Git repositories for worktree development" description = "Tool to set up Git repositories for worktree development"
edition.workspace = true edition.workspace = true
@@ -12,5 +12,5 @@ repository.workspace = true
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.1.0", path = "../git" } git = { version = "0.2.0", path = "../git" }
indicatif = "0.17" indicatif = "0.17"

View File

@@ -39,10 +39,9 @@ fn main() -> Result<()> {
// This behavior follows git itself // This behavior follows git itself
None => { None => {
let start = args.repo_url.rfind("/").unwrap() + 1; let start = args.repo_url.rfind("/").unwrap() + 1;
let end = match args.repo_url.rfind(".git") let end = match args.repo_url.rfind(".git") {
{
Some(index) => index, Some(index) => index,
None => args.repo_url.len() None => args.repo_url.len(),
}; };
args.repo_url[start..end].to_owned() args.repo_url[start..end].to_owned()
@@ -53,10 +52,13 @@ fn main() -> Result<()> {
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: {}", 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, &target_dir)?; Git::clone_bare_repo(&args.repo_url, &target_dir)?;
@@ -71,6 +73,9 @@ fn main() -> Result<()> {
Git::fetch_remotes(&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 '{}'.", target_dir).green()); println!(
"{}",
format!("You can now create worktrees in '{target_dir}'.").green()
);
Ok(()) Ok(())
} }