Skip to content

Commit

Permalink
undo: always preserve git_refs by default
Browse files Browse the repository at this point in the history
The result is equivalent to jj-vcs#1541
but with many more tests
  • Loading branch information
ilyagr committed Jun 26, 2023
1 parent 3419adf commit a6be09b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/commands/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,12 @@ fn view_with_desired_portions_restored(

fn process_what_arg(
what_arg: &[UndoWhatToRestore],
colocated: bool,
_colocated: bool,
) -> BTreeSet<UndoWhatToRestore> {
if !what_arg.is_empty() {
what_arg.iter().cloned().collect()
} else {
let mut default_what =
btreeset!(UndoWhatToRestore::Repo, UndoWhatToRestore::RemoteTracking);
if !colocated {
default_what.insert(UndoWhatToRestore::GitTracking);
}
let default_what = btreeset!(UndoWhatToRestore::Repo, UndoWhatToRestore::RemoteTracking);
default_what
}
}
Expand Down
9 changes: 4 additions & 5 deletions tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,11 @@ fn test_git_fetch_undo() {
"###);
// Now try to fetch just one branch
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "b"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
◉ c7d4bdcbc215 descr_for_b b
◉ ff36dc55760e descr_for_trunk1
│ @ 230dd059e1b0
├─╯
@ 230dd059e1b0
◉ 000000000000
"###);
}
Expand Down
30 changes: 23 additions & 7 deletions tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fn test_git_export_undo() {

// "git export" can't be undone.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "undo"]), @r###"
Nothing changed.
"###);
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
Expand All @@ -118,7 +119,9 @@ fn test_git_export_undo() {

// This would re-export branch "a" as the internal state has been rolled back.
// It might be better to preserve the state, and say "Nothing changed" here.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @r###"
Nothing changed.
"###);
}

#[test]
Expand Down Expand Up @@ -149,11 +152,17 @@ fn test_git_import_undo() {
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @r###"
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a (deleted)
@git: 230dd059e1b0 (no description set)
"###);
// Try "git import" again, which should re-import the branch "a".
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @r###"
Nothing changed.
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: 230dd059e1b0 (no description set)
a (deleted)
@git: 230dd059e1b0 (no description set)
"###);

// If we don't restore the git_refs, undoing the import removes the local branch
Expand All @@ -169,6 +178,7 @@ fn test_git_import_undo() {
],
);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a (deleted)
Expand Down Expand Up @@ -244,7 +254,10 @@ fn test_git_import_move_export_with_default_undo() {
Working copy now at: 230dd059e1b0 (no description set)
Parent commit : 000000000000 (no description set)
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a (deleted)
@git: 096dc80da670 (no description set)
"###);
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
(
Expand All @@ -258,9 +271,12 @@ fn test_git_import_move_export_with_default_undo() {

// The last branch "a" state is imported from git. No idea what's the most
// intuitive result here.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @r###"
Nothing changed.
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: 096dc80da670 (no description set)
a (deleted)
@git: 096dc80da670 (no description set)
"###);
}

Expand Down
9 changes: 3 additions & 6 deletions tests/test_undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ fn test_git_push_undo() {
// made us think it updated from v1 to v2 (instead of the no-op it could
// have been).
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main (conflicted):
- 0cffb6146141 AA
+ 0a3e99f08a48 CC
+ 8c05de152218 BB
@origin (behind by 1 commits): 8c05de152218 BB
main: 0a3e99f08a48 CC
@origin (ahead by 1 commits, behind by 1 commits): 0cffb6146141 AA
"###);
}

Expand Down Expand Up @@ -116,7 +113,7 @@ fn test_git_push_undo_with_import() {
// was essentially a no-op.
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main: 0a3e99f08a48 CC
@origin (ahead by 1 commits, behind by 1 commits): 8c05de152218 BB
@origin (ahead by 1 commits, behind by 1 commits): 0cffb6146141 AA
"###);
}

Expand Down

0 comments on commit a6be09b

Please sign in to comment.