mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-27 07:46:13 +00:00
fix(migrate): refuse linked-worktree submodules and relative worktree links
Resolve the new worktree's gitdir pointer relative to its own dir, and mention link repair in the interrupted-migration message. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65bd95f1f7
commit
a9f8fe4a50
2 files changed
+51
-3
No files matched your search
@@ -215,7 +215,7 @@ fn preflight(root: &Path) -> Result<(String, Vec<Linked>), MigrateError> {
|
|||||||
}
|
}
|
||||||
if root.join(STAGE).exists() {
|
if root.join(STAGE).exists() {
|
||||||
return refuse(format!(
|
return refuse(format!(
|
||||||
"{STAGE} exists: a previous migration was interrupted. Your files are in {STAGE} and the git dir in .bare; restore from the backup tar or move them back by hand"
|
"{STAGE} exists: a previous migration was interrupted. Your files are in {STAGE} and the git dir in .bare; restore from the backup tar or move them back by hand. Linked worktrees may also need their .git link files restored from the backup tars or `git worktree repair`"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !dotgit.is_dir() {
|
if !dotgit.is_dir() {
|
||||||
@@ -251,9 +251,25 @@ fn preflight(root: &Path) -> Result<(String, Vec<Linked>), MigrateError> {
|
|||||||
) {
|
) {
|
||||||
return refuse("sparse checkout / per-worktree config is not supported yet");
|
return refuse("sparse checkout / per-worktree config is not supported yet");
|
||||||
}
|
}
|
||||||
if root.join(".gitmodules").exists() || dotgit.join("modules").exists() {
|
if root.join(".gitmodules").exists()
|
||||||
|
|| dotgit.join("modules").exists()
|
||||||
|
|| list_ids(&dotgit)
|
||||||
|
.iter()
|
||||||
|
.any(|id| dotgit.join("worktrees").join(id).join("modules").exists())
|
||||||
|
{
|
||||||
return refuse("submodules are not supported yet");
|
return refuse("submodules are not supported yet");
|
||||||
}
|
}
|
||||||
|
for key in ["worktree.useRelativePaths", "extensions.relativeWorktrees"] {
|
||||||
|
if matches!(
|
||||||
|
git.probe(&["config", "--type=bool", "--get", key])?
|
||||||
|
.as_deref(),
|
||||||
|
Some("true")
|
||||||
|
) {
|
||||||
|
return refuse(format!(
|
||||||
|
"{key} (relative worktree links) is not supported yet"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
let linked = linked_worktrees(root, &git)?;
|
let linked = linked_worktrees(root, &git)?;
|
||||||
Ok((branch, linked))
|
Ok((branch, linked))
|
||||||
}
|
}
|
||||||
@@ -346,6 +362,11 @@ fn linked_worktrees(root: &Path, git: &Git) -> Result<Vec<Linked>, MigrateError>
|
|||||||
"operation in progress ({f}) in linked worktree {shown}: finish or abort it first"
|
"operation in progress ({f}) in linked worktree {shown}: finish or abort it first"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if old_path.join(".gitmodules").exists() {
|
||||||
|
return refuse(format!(
|
||||||
|
"linked worktree {shown} has submodules; not supported yet"
|
||||||
|
));
|
||||||
|
}
|
||||||
let orig_gitdir = fs::read_to_string(meta.join("gitdir"))?;
|
let orig_gitdir = fs::read_to_string(meta.join("gitdir"))?;
|
||||||
linked.push(Linked {
|
linked.push(Linked {
|
||||||
old_path,
|
old_path,
|
||||||
@@ -588,7 +609,7 @@ fn run_steps(
|
|||||||
let meta = pointer
|
let meta = pointer
|
||||||
.trim()
|
.trim()
|
||||||
.strip_prefix("gitdir: ")
|
.strip_prefix("gitdir: ")
|
||||||
.map(PathBuf::from)
|
.map(|m| wt.join(m))
|
||||||
.ok_or("unexpected .git file in new worktree")?;
|
.ok_or("unexpected .git file in new worktree")?;
|
||||||
p.wt_meta = Some(meta.clone());
|
p.wt_meta = Some(meta.clone());
|
||||||
hook(inject, Step::WorktreeAdded)?;
|
hook(inject, Step::WorktreeAdded)?;
|
||||||
|
|||||||
@@ -204,6 +204,33 @@ fn refuses_unsafe_situations_without_touching_anything() {
|
|||||||
"{m}"
|
"{m}"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let subw = base.join("subw");
|
||||||
|
let g = init(&subw);
|
||||||
|
commit(&g, "a", "1");
|
||||||
|
let sw = base.join("subw-wt");
|
||||||
|
g.run(&["worktree", "add", "-q", "-b", "x", sw.to_str().unwrap()])
|
||||||
|
.unwrap();
|
||||||
|
fs::write(sw.join(".gitmodules"), "").unwrap();
|
||||||
|
assert!(refused(migrate(&subw, "m", &bk, "1")).contains("submodules"));
|
||||||
|
let subm2 = base.join("subm2");
|
||||||
|
let g = init(&subm2);
|
||||||
|
commit(&g, "a", "1");
|
||||||
|
let sw2 = base.join("subm2-wt");
|
||||||
|
g.run(&["worktree", "add", "-q", "-b", "x", sw2.to_str().unwrap()])
|
||||||
|
.unwrap();
|
||||||
|
let meta = fs::read_to_string(sw2.join(".git")).unwrap();
|
||||||
|
let meta = meta.trim().strip_prefix("gitdir: ").unwrap();
|
||||||
|
fs::create_dir_all(std::path::Path::new(meta).join("modules/m")).unwrap();
|
||||||
|
assert!(refused(migrate(&subm2, "m", &bk, "1")).contains("submodules"));
|
||||||
|
|
||||||
|
let rel = base.join("rel");
|
||||||
|
let g = init(&rel);
|
||||||
|
commit(&g, "a", "1");
|
||||||
|
g.run(&["config", "worktree.useRelativePaths", "true"])
|
||||||
|
.unwrap();
|
||||||
|
assert!(refused(migrate(&rel, "m", &bk, "1")).contains("relative"));
|
||||||
|
assert!(rel.join(".git").is_dir());
|
||||||
|
|
||||||
let done = base.join("done");
|
let done = base.join("done");
|
||||||
let g = init(&done);
|
let g = init(&done);
|
||||||
commit(&g, "a", "1");
|
commit(&g, "a", "1");
|
||||||
|
|||||||
Reference in new issue
Block a user