-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workspace: abandon discardable working copy on forget
Forgetting a workspace removes its working-copy commit, so it makes sense for it to be abandoned if it is discardable just like editing a new commit will cause the old commit to be abandoned if it is discardable.
- Loading branch information
Showing
6 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -628,14 +628,11 @@ fn test_workspaces_forget() { | |
insta::assert_snapshot!(stderr, @""); | ||
|
||
// The old working copy doesn't get an "@" in the log output | ||
// TODO: We should abandon the empty working copy commit | ||
// TODO: It seems useful to still have the "secondary@" marker here even though | ||
// there's only one workspace. We should show it when the command is not run | ||
// from that workspace. | ||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" | ||
◉ 18463f438cc9 | ||
│ ◉ 909d51b17292 | ||
├─╯ | ||
◉ 4e8f9d2be039 | ||
◉ 000000000000 | ||
"###); | ||
|
@@ -695,7 +692,7 @@ fn test_workspaces_forget_multi_transaction() { | |
// the op log should have multiple workspaces forgotten in a single tx | ||
let stdout = test_env.jj_cmd_success(&main_path, &["op", "log", "--limit", "1"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
@ 6c88cdee70e6 [email protected] 2001-02-03 04:05:12.000 +07:00 - 2001-02-03 04:05:12.000 +07:00 | ||
@ f91852cb278f [email protected] 2001-02-03 04:05:12.000 +07:00 - 2001-02-03 04:05:12.000 +07:00 | ||
│ forget workspaces second, third | ||
│ args: jj workspace forget second third | ||
"###); | ||
|
@@ -712,6 +709,65 @@ fn test_workspaces_forget_multi_transaction() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_workspaces_forget_abandon_commits() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "main"]); | ||
let main_path = test_env.env_root().join("main"); | ||
|
||
std::fs::write(main_path.join("file"), "contents").unwrap(); | ||
|
||
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../second"]); | ||
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../third"]); | ||
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../fourth"]); | ||
let third_path = test_env.env_root().join("third"); | ||
test_env.jj_cmd_ok(&third_path, &["edit", "second@"]); | ||
let fourth_path = test_env.env_root().join("fourth"); | ||
test_env.jj_cmd_ok(&fourth_path, &["edit", "second@"]); | ||
|
||
// there should be four workspaces, three of which are at the same empty commit | ||
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
default: qpvuntsm 4e8f9d2b (no description set) | ||
fourth: uuqppmxq 57d63245 (empty) (no description set) | ||
second: uuqppmxq 57d63245 (empty) (no description set) | ||
third: uuqppmxq 57d63245 (empty) (no description set) | ||
"###); | ||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" | ||
◉ 57d63245a308 fourth@ second@ third@ | ||
│ @ 4e8f9d2be039 default@ | ||
├─╯ | ||
◉ 000000000000 | ||
"###); | ||
|
||
// delete the default workspace (should not abandon commit since not empty) | ||
test_env.jj_cmd_success(&main_path, &["workspace", "forget", "default"]); | ||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" | ||
◉ 57d63245a308 fourth@ second@ third@ | ||
│ ◉ 4e8f9d2be039 | ||
├─╯ | ||
◉ 000000000000 | ||
"###); | ||
|
||
// delete the second workspace (should not abandon commit since other workspaces | ||
// still have commit checked out) | ||
test_env.jj_cmd_success(&main_path, &["workspace", "forget", "second"]); | ||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" | ||
◉ 57d63245a308 fourth@ third@ | ||
│ ◉ 4e8f9d2be039 | ||
├─╯ | ||
◉ 000000000000 | ||
"###); | ||
|
||
// delete the last 2 workspaces (commit should be abandoned now even though | ||
// forgotten in same tx) | ||
test_env.jj_cmd_success(&main_path, &["workspace", "forget", "third", "fourth"]); | ||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###" | ||
◉ 4e8f9d2be039 | ||
◉ 000000000000 | ||
"###); | ||
} | ||
|
||
/// Test context of commit summary template | ||
#[test] | ||
fn test_list_workspaces_template() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters