Update libs
This commit is contained in:
@@ -9,10 +9,10 @@ license-file.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
anyhow = "1.0"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
colored = "3.0"
|
||||
indicatif = "0.17"
|
||||
dirs = "6.0"
|
||||
git = { version = "0.1.0", path = "../git" }
|
||||
indicatif = "0.17"
|
||||
thiserror = { version = "2.0" }
|
||||
command-with-spinner = { version = "0.1.0", path = "../command-with-spinner" }
|
||||
|
@@ -1,12 +1,11 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{ArgAction, Parser};
|
||||
use colored::*;
|
||||
|
||||
use command_with_spinner::run_command;
|
||||
use git::Git;
|
||||
|
||||
/// Tool to create git worktrees with convenient branch management
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -40,86 +39,6 @@ struct Args {
|
||||
no_color: bool,
|
||||
}
|
||||
|
||||
/// 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
|
||||
fn update_remote(branch: &str, create_upstream: bool) -> Result<()> {
|
||||
// Do nothing if create_upstream is disabled
|
||||
|
Reference in New Issue
Block a user