Compare commits
1 Commits
c3c1c98913
...
v0.6.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f878793fd |
@@ -1,18 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
def test_worktree_status():
|
||||||
@pytest.mark.parametrize("has_config", [True, False])
|
|
||||||
def test_worktree_status(has_config):
|
|
||||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
||||||
if has_config:
|
|
||||||
with open(os.path.join(base_dir, "grm.toml"), "w") as f:
|
|
||||||
f.write("")
|
|
||||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
||||||
assert cmd.returncode == 0
|
assert cmd.returncode == 0
|
||||||
|
|
||||||
@@ -48,30 +40,3 @@ def test_worktree_status_non_git():
|
|||||||
assert cmd.returncode != 0
|
assert cmd.returncode != 0
|
||||||
assert len(cmd.stdout) == 0
|
assert len(cmd.stdout) == 0
|
||||||
assert len(cmd.stderr) != 0
|
assert len(cmd.stderr) != 0
|
||||||
|
|
||||||
|
|
||||||
def test_worktree_status_warn_with_non_worktree_dir():
|
|
||||||
with TempGitRepositoryWorktree() as (base_dir, _commit):
|
|
||||||
cmd = grm(["wt", "add", "test"], cwd=base_dir)
|
|
||||||
assert cmd.returncode == 0
|
|
||||||
|
|
||||||
shell(
|
|
||||||
f"""
|
|
||||||
cd {base_dir}
|
|
||||||
mkdir not_a_worktree
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
cmd = grm(["wt", "status"], cwd=base_dir)
|
|
||||||
|
|
||||||
assert cmd.returncode == 0
|
|
||||||
assert len(cmd.stdout) != 0
|
|
||||||
assert len(cmd.stderr) != 0
|
|
||||||
assert (
|
|
||||||
re.match(
|
|
||||||
".*error.*not_a_worktree.*not a valid worktree directory",
|
|
||||||
cmd.stderr,
|
|
||||||
re.IGNORECASE,
|
|
||||||
)
|
|
||||||
is not None
|
|
||||||
)
|
|
||||||
|
|||||||
12
src/lib.rs
12
src/lib.rs
@@ -474,15 +474,15 @@ pub fn add_worktree(
|
|||||||
|
|
||||||
let config = repo::read_worktree_root_config(directory)?;
|
let config = repo::read_worktree_root_config(directory)?;
|
||||||
|
|
||||||
if repo.find_worktree(name).is_ok() {
|
let path = match subdirectory {
|
||||||
|
Some(dir) => dir.join(name),
|
||||||
|
None => Path::new(name).to_path_buf(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if repo.find_worktree(&path).is_ok() {
|
||||||
return Err(format!("Worktree {} already exists", &name));
|
return Err(format!("Worktree {} already exists", &name));
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = match subdirectory {
|
|
||||||
Some(dir) => directory.join(dir).join(name),
|
|
||||||
None => directory.join(Path::new(name)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut remote_branch_exists = false;
|
let mut remote_branch_exists = false;
|
||||||
|
|
||||||
let default_checkout = || repo.default_branch()?.to_commit();
|
let default_checkout = || repo.default_branch()?.to_commit();
|
||||||
|
|||||||
@@ -672,8 +672,10 @@ impl Repo {
|
|||||||
self.0.config().map_err(convert_libgit2_error)
|
self.0.config().map_err(convert_libgit2_error)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_worktree(&self, name: &str) -> Result<(), String> {
|
pub fn find_worktree(&self, path: &Path) -> Result<(), String> {
|
||||||
self.0.find_worktree(name).map_err(convert_libgit2_error)?;
|
self.0
|
||||||
|
.find_worktree(path.to_str().expect("Worktree path is not valid utf-8"))
|
||||||
|
.map_err(convert_libgit2_error)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/table.rs
26
src/table.rs
@@ -1,5 +1,3 @@
|
|||||||
use crate::Repo;
|
|
||||||
|
|
||||||
use comfy_table::{Cell, Table};
|
use comfy_table::{Cell, Table};
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -132,11 +130,25 @@ pub fn get_worktree_status_table(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for worktree in Repo::find_unmanaged_worktrees(repo, directory).unwrap() {
|
for entry in std::fs::read_dir(&directory).map_err(|error| error.to_string())? {
|
||||||
errors.push(format!(
|
let dirname = crate::path_as_string(
|
||||||
"Found {}, which is not a valid worktree directory!",
|
entry
|
||||||
&worktree
|
.map_err(|error| error.to_string())?
|
||||||
));
|
.path()
|
||||||
|
.strip_prefix(&directory)
|
||||||
|
// this unwrap is safe, as we can be sure that each subentry of
|
||||||
|
// &directory also has the prefix &dir
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
if dirname == crate::GIT_MAIN_WORKTREE_DIRECTORY {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if !&worktrees.iter().any(|worktree| worktree.name() == dirname) {
|
||||||
|
errors.push(format!(
|
||||||
|
"Found {}, which is not a valid worktree directory!",
|
||||||
|
&dirname
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok((table, errors))
|
Ok((table, errors))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user