Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 31b9757ef3 | |||
| defb3d1b7d | |||
| e6b654e990 | |||
| 29ddc647e3 | |||
| 67c3e40108 | |||
| 7363ed48b4 | |||
| 96943c1483 | |||
| 9f7195282f | |||
| 30480fb568 | |||
| c3aaea3332 | |||
| fad6f71876 | |||
| 73158e3d47 | |||
| 6f4ae88260 | |||
| a8f8803a92 | |||
| 581a513ebd | |||
| f1e212ead9 | |||
| bc3001a4e6 | |||
| c4fd1d0452 | |||
| 1a65a163a1 | |||
| 4f68a563c6 | |||
| e04e8ceeeb | |||
|
|
b2542b341e | ||
| d402c1f8ce |
45
Cargo.lock
generated
45
Cargo.lock
generated
@@ -101,7 +101,7 @@ version = "3.1.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
|
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.4.0",
|
"heck",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -119,9 +119,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "comfy-table"
|
name = "comfy-table"
|
||||||
version = "5.0.1"
|
version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b103d85ca6e209388771bfb7aa6b68a7aeec4afbf6f0a0264bfbf50360e5212e"
|
checksum = "121d8a5b0346092c18a4b2fd6f620d7a06f0eb7ac0a45860939a0884bc579c56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"strum",
|
"strum",
|
||||||
@@ -332,7 +332,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "git-repo-manager"
|
name = "git-repo-manager"
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"comfy-table",
|
"comfy-table",
|
||||||
@@ -371,15 +371,6 @@ version = "0.11.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-segmentation",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@@ -532,9 +523,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libz-sys"
|
name = "libz-sys"
|
||||||
version = "1.1.6"
|
version = "1.1.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e"
|
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -620,9 +611,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.9.73"
|
version = "0.9.74"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0"
|
checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"cc",
|
"cc",
|
||||||
@@ -646,9 +637,9 @@ checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.0"
|
version = "0.12.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
|
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
@@ -1005,17 +996,17 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strum"
|
name = "strum"
|
||||||
version = "0.23.0"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb"
|
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strum_macros"
|
name = "strum_macros"
|
||||||
version = "0.23.1"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38"
|
checksum = "9550962e7cf70d9980392878dfaf1dcc3ece024f4cf3bf3c46b978d0bad61d6c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.3.3",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
@@ -1176,12 +1167,6 @@ dependencies = [
|
|||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-segmentation"
|
|
||||||
version = "1.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "git-repo-manager"
|
name = "git-repo-manager"
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
authors = [
|
authors = [
|
||||||
@@ -64,7 +64,7 @@ version = "=0.15.0"
|
|||||||
version = "=1.5.6"
|
version = "=1.5.6"
|
||||||
|
|
||||||
[dependencies.comfy-table]
|
[dependencies.comfy-table]
|
||||||
version = "=5.0.1"
|
version = "=6.0.0"
|
||||||
|
|
||||||
[dependencies.serde_yaml]
|
[dependencies.serde_yaml]
|
||||||
version = "=0.8.24"
|
version = "=0.8.24"
|
||||||
|
|||||||
8
Justfile
8
Justfile
@@ -2,7 +2,7 @@ set positional-arguments
|
|||||||
|
|
||||||
target := "x86_64-unknown-linux-musl"
|
target := "x86_64-unknown-linux-musl"
|
||||||
|
|
||||||
check: test
|
check: fmt-check lint test
|
||||||
cargo check
|
cargo check
|
||||||
cargo fmt --check
|
cargo fmt --check
|
||||||
cargo clippy --no-deps -- -Dwarnings
|
cargo clippy --no-deps -- -Dwarnings
|
||||||
@@ -11,8 +11,12 @@ fmt:
|
|||||||
cargo fmt
|
cargo fmt
|
||||||
git ls-files | grep '\.py$' | xargs black
|
git ls-files | grep '\.py$' | xargs black
|
||||||
|
|
||||||
|
fmt-check:
|
||||||
|
cargo fmt --check
|
||||||
|
git ls-files | grep '\.py$' | xargs black --check
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
cargo clippy --no-deps
|
cargo clippy --no-deps -- -Dwarnings
|
||||||
|
|
||||||
lint-fix:
|
lint-fix:
|
||||||
cargo clippy --no-deps --fix
|
cargo clippy --no-deps --fix
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ impl Provider for Github {
|
|||||||
fn get_current_user(&self) -> Result<String, ApiErrorResponse<GithubApiErrorResponse>> {
|
fn get_current_user(&self) -> Result<String, ApiErrorResponse<GithubApiErrorResponse>> {
|
||||||
Ok(super::call::<GithubUser, GithubApiErrorResponse>(
|
Ok(super::call::<GithubUser, GithubApiErrorResponse>(
|
||||||
&format!("{GITHUB_API_BASEURL}/user"),
|
&format!("{GITHUB_API_BASEURL}/user"),
|
||||||
&Self::auth_header_key(),
|
Self::auth_header_key(),
|
||||||
&self.secret_token(),
|
self.secret_token(),
|
||||||
Some(ACCEPT_HEADER_JSON),
|
Some(ACCEPT_HEADER_JSON),
|
||||||
)?
|
)?
|
||||||
.username)
|
.username)
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ impl Provider for Gitlab {
|
|||||||
fn get_current_user(&self) -> Result<String, ApiErrorResponse<GitlabApiErrorResponse>> {
|
fn get_current_user(&self) -> Result<String, ApiErrorResponse<GitlabApiErrorResponse>> {
|
||||||
Ok(super::call::<GitlabUser, GitlabApiErrorResponse>(
|
Ok(super::call::<GitlabUser, GitlabApiErrorResponse>(
|
||||||
&format!("{}/api/v4/user", self.api_url()),
|
&format!("{}/api/v4/user", self.api_url()),
|
||||||
&Self::auth_header_key(),
|
Self::auth_header_key(),
|
||||||
&self.secret_token(),
|
self.secret_token(),
|
||||||
Some(ACCEPT_HEADER_JSON),
|
Some(ACCEPT_HEADER_JSON),
|
||||||
)?
|
)?
|
||||||
.username)
|
.username)
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ pub trait Provider {
|
|||||||
for repo in repos {
|
for repo in repos {
|
||||||
let namespace = repo.namespace();
|
let namespace = repo.namespace();
|
||||||
|
|
||||||
let mut repo = repo.into_repo_config(&self.name(), worktree_setup, force_ssh);
|
let mut repo = repo.into_repo_config(self.name(), worktree_setup, force_ssh);
|
||||||
|
|
||||||
// Namespace is already part of the hashmap key. I'm not too happy
|
// Namespace is already part of the hashmap key. I'm not too happy
|
||||||
// about the data exchange format here.
|
// about the data exchange format here.
|
||||||
|
|||||||
22
src/repo.rs
22
src/repo.rs
@@ -1056,12 +1056,12 @@ impl RepoHandle {
|
|||||||
|
|
||||||
// Note that <remote>/HEAD only exists after a normal clone, there is no way to get the
|
// Note that <remote>/HEAD only exists after a normal clone, there is no way to get the
|
||||||
// remote HEAD afterwards. So this is a "best effort" approach.
|
// remote HEAD afterwards. So this is a "best effort" approach.
|
||||||
if let Ok(remote_head) = self.find_remote_branch(&remote_name, "HEAD") {
|
if let Ok(remote_head) = self.find_remote_branch(remote_name, "HEAD") {
|
||||||
if let Some(pointer_name) = remote_head.as_reference().symbolic_target() {
|
if let Some(pointer_name) = remote_head.as_reference().symbolic_target() {
|
||||||
if let Some(local_branch_name) =
|
if let Some(local_branch_name) =
|
||||||
pointer_name.strip_prefix(&format!("refs/remotes/{}/", remote_name))
|
pointer_name.strip_prefix(&format!("refs/remotes/{}/", remote_name))
|
||||||
{
|
{
|
||||||
return Ok(Some(self.find_local_branch(&local_branch_name)?));
|
return Ok(Some(self.find_local_branch(local_branch_name)?));
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Remote HEAD ({}) pointer is invalid", pointer_name);
|
eprintln!("Remote HEAD ({}) pointer is invalid", pointer_name);
|
||||||
}
|
}
|
||||||
@@ -1088,7 +1088,7 @@ impl RepoHandle {
|
|||||||
|
|
||||||
if remotes.len() == 1 {
|
if remotes.len() == 1 {
|
||||||
let remote_name = &remotes[0];
|
let remote_name = &remotes[0];
|
||||||
if let Some(default_branch) = self.get_remote_default_branch(&remote_name)? {
|
if let Some(default_branch) = self.get_remote_default_branch(remote_name)? {
|
||||||
return Ok(default_branch);
|
return Ok(default_branch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1099,17 +1099,13 @@ impl RepoHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !default_branches.is_empty() {
|
if !default_branches.is_empty()
|
||||||
if default_branches.len() == 1 {
|
&& (default_branches.len() == 1
|
||||||
return Ok(default_branches.remove(0));
|
|| default_branches
|
||||||
} else {
|
|
||||||
if default_branches
|
|
||||||
.windows(2)
|
.windows(2)
|
||||||
.all(|w| w[0].name() == w[1].name())
|
.all(|w| w[0].name() == w[1].name()))
|
||||||
{
|
{
|
||||||
return Ok(default_branches.remove(0));
|
return Ok(default_branches.remove(0));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,95 +5,6 @@ use super::repo;
|
|||||||
|
|
||||||
pub const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
|
pub const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::Command;
|
|
||||||
use tempdir::TempDir;
|
|
||||||
|
|
||||||
fn init_empty_repo() -> PathBuf {
|
|
||||||
let directory = TempDir::new("grm-worktree").unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.args(["init", "."])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("touch")
|
|
||||||
.args(["test"])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.args(["add", "test"])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.args(["commit", "-m", "Initial commit"])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("bash")
|
|
||||||
.args(["-c", "git ls-files | xargs rm -rf"])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("mv")
|
|
||||||
.args([".git", GIT_MAIN_WORKTREE_DIRECTORY])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
Command::new("git")
|
|
||||||
.args([
|
|
||||||
"--git-dir",
|
|
||||||
GIT_MAIN_WORKTREE_DIRECTORY,
|
|
||||||
"config",
|
|
||||||
"core.bare",
|
|
||||||
"true",
|
|
||||||
])
|
|
||||||
.current_dir(directory.path())
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
directory.into_path()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_new_worktree() {
|
|
||||||
let repo_path = init_empty_repo();
|
|
||||||
|
|
||||||
let out = add_worktree(&repo_path, "test", None, None, true);
|
|
||||||
assert!(out.is_ok());
|
|
||||||
let repo = git2::Repository::open(repo_path.join("test")).unwrap();
|
|
||||||
assert_eq!(repo.head().unwrap().shorthand().unwrap(), "test");
|
|
||||||
assert!(repo
|
|
||||||
.find_branch("test", git2::BranchType::Local)
|
|
||||||
.unwrap()
|
|
||||||
.upstream()
|
|
||||||
.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_new_worktree_with_remote_track() {
|
|
||||||
let repo_path = init_empty_repo();
|
|
||||||
|
|
||||||
let out = add_worktree(&repo_path, "test", None, Some(("origin", "test")), true);
|
|
||||||
assert!(out.is_ok());
|
|
||||||
let repo = git2::Repository::open(repo_path.join("test")).unwrap();
|
|
||||||
assert_eq!(repo.head().unwrap().shorthand().unwrap(), "test");
|
|
||||||
assert_eq!(
|
|
||||||
repo.find_branch("test", git2::BranchType::Local)
|
|
||||||
.unwrap()
|
|
||||||
.upstream()
|
|
||||||
.unwrap()
|
|
||||||
.name()
|
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
|
||||||
"test"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The logic about the base branch and the tracking branch is as follows:
|
// The logic about the base branch and the tracking branch is as follows:
|
||||||
//
|
//
|
||||||
// * If a branch with the same name does not exist and no track is given, use the default
|
// * If a branch with the same name does not exist and no track is given, use the default
|
||||||
@@ -144,9 +55,9 @@ pub fn add_worktree(
|
|||||||
if let Ok(local_upstream_branch) = branchref.upstream() {
|
if let Ok(local_upstream_branch) = branchref.upstream() {
|
||||||
if remote_branch.name()? != local_upstream_branch.name()? {
|
if remote_branch.name()? != local_upstream_branch.name()? {
|
||||||
print_warning(&format!(
|
print_warning(&format!(
|
||||||
"You specified a tracking branch ({}) for an existing branch ({}), but \
|
"You specified a tracking branch ({}/{}) for an existing branch ({}), but \
|
||||||
it differs from the current upstream ({}). Will keep current upstream"
|
it differs from the current upstream ({}). Will keep current upstream"
|
||||||
, format!("{}/{}", remote_name, remote_branch_name), branchref.name()?, local_upstream_branch.name()?))
|
, remote_name, remote_branch_name, branchref.name()?, local_upstream_branch.name()?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user