Skip to content

Commit 3776420

Browse files
committed
cli: print warning about git clean -fdx when creating colocated repo
We hear every now and then from users who have run `git clean -fdx` and accidentally delete their repo. Let's at least warn users about it when the create a colocated repo. We could perhaps allow the `.jj/` directory to be inside a `.git/` directory like Sapling does, but that seems a little ugly and it's a larger change.
1 parent ba24140 commit 3776420

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

cli/src/commands/git/clone.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ pub fn cmd_git_clone(
162162
tx.finish(ui, "check out git remote's default branch")?;
163163
}
164164
}
165+
166+
if args.colocate {
167+
writeln!(
168+
ui.hint_default(),
169+
r"Running `git clean -xdf` will remove `.jj/`!",
170+
)?;
171+
}
172+
165173
Ok(())
166174
}
167175

cli/src/commands/git/init.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ pub fn cmd_git_init(
112112
r#"Initialized repo in "{}""#,
113113
relative_wc_path.display()
114114
)?;
115+
if args.colocate {
116+
writeln!(
117+
ui.hint_default(),
118+
r"Running `git clean -xdf` will remove `.jj/`!",
119+
)?;
120+
}
115121

116122
Ok(())
117123
}

cli/tests/test_git_clone.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ fn test_git_clone_colocate() {
197197
------- stderr -------
198198
Fetching into new repo in "$TEST_ENV/empty"
199199
Nothing changed.
200+
Hint: Running `git clean -xdf` will remove `.jj/`!
200201
[EOF]
201202
"#);
202203

@@ -220,6 +221,7 @@ fn test_git_clone_colocate() {
220221
Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set)
221222
Parent commit (@-) : qomsplrm ebeb70d8 main | message
222223
Added 1 files, modified 0 files, removed 0 files
224+
Hint: Running `git clean -xdf` will remove `.jj/`!
223225
[EOF]
224226
"#);
225227
let clone_dir = test_env.work_dir("clone");
@@ -365,6 +367,7 @@ fn test_git_clone_colocate() {
365367
Working copy (@) now at: vzqnnsmr fea36bca (empty) (no description set)
366368
Parent commit (@-) : qomsplrm ebeb70d8 main | message
367369
Added 1 files, modified 0 files, removed 0 files
370+
Hint: Running `git clean -xdf` will remove `.jj/`!
368371
[EOF]
369372
"#);
370373
}

cli/tests/test_git_colocated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ fn test_git_colocated_operation_cleanup() {
15391539
insta::assert_snapshot!(output, @r#"
15401540
------- stderr -------
15411541
Initialized repo in "repo"
1542+
Hint: Running `git clean -xdf` will remove `.jj/`!
15421543
[EOF]
15431544
"#);
15441545

cli/tests/test_git_init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ fn test_git_init_colocated_via_flag_git_dir_exists() {
776776
------- stderr -------
777777
Done importing changes from the underlying Git repo.
778778
Initialized repo in "repo"
779+
Hint: Running `git clean -xdf` will remove `.jj/`!
779780
[EOF]
780781
"#);
781782

@@ -806,6 +807,7 @@ fn test_git_init_colocated_via_flag_git_dir_not_exists() {
806807
insta::assert_snapshot!(output, @r#"
807808
------- stderr -------
808809
Initialized repo in "repo"
810+
Hint: Running `git clean -xdf` will remove `.jj/`!
809811
[EOF]
810812
"#);
811813
// No HEAD ref is available yet

0 commit comments

Comments
 (0)