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>
This commit is contained in:
2025-07-03 23:43:13 +02:00
parent cf5b30015a
commit 5d745678f3
3 changed files with 64 additions and 67 deletions

View File

@@ -21,16 +21,14 @@ impl Git {
// 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
]);
cmd.args(["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(()),
Err(_) => Err(GitError::FailedNoCode.into())
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
@@ -48,14 +46,16 @@ impl Git {
let mut cmd = Command::new("git");
cmd.args([
"--git-dir", &bare_dir_str,
"--git-dir",
&bare_dir_str,
"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") {
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 mut cmd = Command::new("git");
cmd.args([
"--git-dir", &bare_dir_str,
"fetch",
"--all"
]);
cmd.args(["--git-dir", &bare_dir_str, "fetch", "--all"]);
match run_command(&mut cmd, "Fetching all remotes") {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into())
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
])
.args(["branch", "--list", branch])
.output()
.context("Failed to check branch existence")?;
@@ -94,12 +86,7 @@ impl Git {
/// 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
])
.args(["ls-remote", "--heads", "origin", branch])
.output()
.context("Failed to check remote branch existence")?;
@@ -109,62 +96,53 @@ impl Git {
/// 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
]);
cmd.args(["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(()),
Err(_) => Err(GitError::FailedNoCode.into())
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
]);
cmd.args(["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(()),
Err(_) => Err(GitError::FailedNoCode.into())
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
]);
cmd.args(["push", "-u", "origin", branch]);
match run_command(&mut cmd, &format!("Creating remote branch {branch}...")) {
Ok(_) => Ok(()),
Err(_) => Err(GitError::FailedNoCode.into())
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}")
]);
cmd.args(["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(()),
Err(_) => Err(GitError::FailedNoCode.into())
Err(_) => Err(GitError::FailedNoCode.into()),
}
}
}