Update libs
This commit is contained in:
@@ -12,5 +12,5 @@ repository.workspace = true
|
||||
anyhow = "1.0"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
colored = "3.0"
|
||||
command-with-spinner = { version = "0.1.0", path = "../command-with-spinner" }
|
||||
git = { version = "0.1.0", path = "../git" }
|
||||
indicatif = "0.17"
|
||||
|
@@ -1,11 +1,8 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use colored::*;
|
||||
|
||||
use command_with_spinner::run_command;
|
||||
use git::Git;
|
||||
|
||||
/// Tool to set up Git repositories for worktree development
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -28,66 +25,6 @@ struct Args {
|
||||
no_color: bool,
|
||||
}
|
||||
|
||||
/// 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<()> {
|
||||
// Parse arguments
|
||||
let args = Args::parse();
|
||||
|
Reference in New Issue
Block a user