diff --git a/crates/grove-core/src/migrate.rs b/crates/grove-core/src/migrate.rs index 2c819d6..8cf143e 100644 --- a/crates/grove-core/src/migrate.rs +++ b/crates/grove-core/src/migrate.rs @@ -215,7 +215,7 @@ fn preflight(root: &Path) -> Result<(String, Vec), MigrateError> { } if root.join(STAGE).exists() { 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() { @@ -251,9 +251,25 @@ fn preflight(root: &Path) -> Result<(String, Vec), MigrateError> { ) { 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"); } + 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)?; Ok((branch, linked)) } @@ -346,6 +362,11 @@ fn linked_worktrees(root: &Path, git: &Git) -> Result, MigrateError> "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"))?; linked.push(Linked { old_path, @@ -588,7 +609,7 @@ fn run_steps( let meta = pointer .trim() .strip_prefix("gitdir: ") - .map(PathBuf::from) + .map(|m| wt.join(m)) .ok_or("unexpected .git file in new worktree")?; p.wt_meta = Some(meta.clone()); hook(inject, Step::WorktreeAdded)?; diff --git a/crates/grove-core/tests/migrate.rs b/crates/grove-core/tests/migrate.rs index f5d2dc5..8be8960 100644 --- a/crates/grove-core/tests/migrate.rs +++ b/crates/grove-core/tests/migrate.rs @@ -204,6 +204,33 @@ fn refuses_unsafe_situations_without_touching_anything() { "{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 g = init(&done); commit(&g, "a", "1");