2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-04-22 04:49:57 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use crate::common::TestEnvironment;
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
/// Test adding a second workspace
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_add_second_workspace() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents").unwrap();
|
2022-11-05 00:15:35 +00:00
|
|
|
test_env.jj_cmd_success(&main_path, &["commit", "-m", "initial"]);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
default: e0e6d5672858 (no description set)
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&main_path,
|
|
|
|
&["workspace", "add", "--name", "second", "../secondary"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout.replace('\\', "/"), @r###"
|
|
|
|
Created workspace in "../secondary"
|
2022-12-21 04:47:10 +00:00
|
|
|
Working copy now at: 397eac932ad3 (no description set)
|
2022-04-22 04:49:57 +00:00
|
|
|
Added 1 files, modified 0 files, removed 0 files
|
|
|
|
"###);
|
|
|
|
|
2023-01-25 16:29:15 +00:00
|
|
|
// Can see the working-copy commit in each workspace in the log output. The "@"
|
|
|
|
// node in the graph indicates the current workspace's working-copy commit.
|
2022-04-22 04:49:57 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 397eac932ad3c349b2659fd2eb035a4dd3da4193 second@
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ e0e6d5672858dc9a57ec5b772b7c4f3270ed0223 default@
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 7d308bc9d934c53c6cc52935192e2d6ac5d78cfd
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 397eac932ad3c349b2659fd2eb035a4dd3da4193 second@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ e0e6d5672858dc9a57ec5b772b7c4f3270ed0223 default@
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 7d308bc9d934c53c6cc52935192e2d6ac5d78cfd
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Both workspaces show up when we list them
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
default: e0e6d5672858 (no description set)
|
|
|
|
second: 397eac932ad3 (no description set)
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test making changes to the working copy in a workspace as it gets rewritten
|
|
|
|
/// from another workspace
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_conflicting_edits() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents\n").unwrap();
|
2022-11-05 00:15:35 +00:00
|
|
|
test_env.jj_cmd_success(&main_path, &["new"]);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
|
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 265af0cdbcc7bb33e3734ad72565c943ce3fb0d4 secondary@
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ 351099fa72cfbb1b34e410e89821efc623295974 default@
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ cf911c223d3e24e001fc8264d6dbf0610804fc40
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Make changes in both working copies
|
|
|
|
std::fs::write(main_path.join("file"), "changed in main\n").unwrap();
|
|
|
|
std::fs::write(secondary_path.join("file"), "changed in second\n").unwrap();
|
2022-10-02 17:09:46 +00:00
|
|
|
// Squash the changes from the main workspace into the initial commit (before
|
2022-04-22 04:49:57 +00:00
|
|
|
// running any command in the secondary workspace
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["squash"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-11-05 00:15:35 +00:00
|
|
|
Working copy now at: fe8f41ed01d6 (no description set)
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
|
2022-10-02 17:09:46 +00:00
|
|
|
// The secondary workspace's working-copy commit was updated
|
2022-04-22 04:49:57 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ a1896a17282f19089a5cec44358d6609910e0513 secondary@
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c0d4a99ef98ada7da8dc73a778bbb747c4178385
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
2022-10-02 17:09:46 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&secondary_path, &["st"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-02-27 07:55:15 +00:00
|
|
|
Error: The working copy is stale (not updated since operation 815bb8fcbd7a).
|
2022-10-02 17:09:46 +00:00
|
|
|
Hint: Run `jj workspace update-stale` to update it.
|
|
|
|
"###);
|
|
|
|
// Same error on second run, and from another command
|
|
|
|
let stderr = test_env.jj_cmd_failure(&secondary_path, &["log"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-02-27 07:55:15 +00:00
|
|
|
Error: The working copy is stale (not updated since operation 815bb8fcbd7a).
|
2022-10-02 17:09:46 +00:00
|
|
|
Hint: Run `jj workspace update-stale` to update it.
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
|
2023-02-26 11:52:06 +00:00
|
|
|
// It was detected that the working copy is now stale.
|
|
|
|
// Since there was an uncommitted change in the working copy, it should
|
2022-04-22 04:49:57 +00:00
|
|
|
// have been committed first (causing divergence)
|
2022-10-02 17:09:46 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-02-26 11:52:06 +00:00
|
|
|
Concurrent modification detected, resolving automatically.
|
|
|
|
Rebased 1 descendant commits onto commits rewritten by other operation
|
2022-10-02 17:09:46 +00:00
|
|
|
Working copy now at: a1896a17282f (no description set)
|
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path),
|
|
|
|
@r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 8d90dc175c874af0dff032d611029dc722d4e108 (divergent)
|
|
|
|
│ ◉ fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
|
2023-02-26 11:52:06 +00:00
|
|
|
├─╯
|
|
|
|
│ @ a1896a17282f19089a5cec44358d6609910e0513 secondary@ (divergent)
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c0d4a99ef98ada7da8dc73a778bbb747c4178385
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
2022-08-18 07:49:32 +00:00
|
|
|
// The stale working copy should have been resolved by the previous command
|
|
|
|
let stdout = get_log_output(&test_env, &secondary_path);
|
|
|
|
assert!(!stdout.starts_with("The working copy is stale"));
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 8d90dc175c874af0dff032d611029dc722d4e108 (divergent)
|
|
|
|
│ ◉ fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
|
2023-02-26 11:52:06 +00:00
|
|
|
├─╯
|
|
|
|
│ @ a1896a17282f19089a5cec44358d6609910e0513 secondary@ (divergent)
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c0d4a99ef98ada7da8dc73a778bbb747c4178385
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-08-18 07:49:32 +00:00
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 02:07:46 +00:00
|
|
|
/// Test a clean working copy that gets rewritten from another workspace
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_updated_by_other() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&main_path, &["new"]);
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
|
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 265af0cdbcc7bb33e3734ad72565c943ce3fb0d4 secondary@
|
2023-02-27 02:07:46 +00:00
|
|
|
│ @ 351099fa72cfbb1b34e410e89821efc623295974 default@
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ cf911c223d3e24e001fc8264d6dbf0610804fc40
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2023-02-27 02:07:46 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Rewrite the check-out commit in one workspace.
|
|
|
|
std::fs::write(main_path.join("file"), "changed in main\n").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["squash"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
Working copy now at: fe8f41ed01d6 (no description set)
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// The secondary workspace's working-copy commit was updated.
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
|
|
|
@ fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ a1896a17282f19089a5cec44358d6609910e0513 secondary@
|
2023-02-27 02:07:46 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c0d4a99ef98ada7da8dc73a778bbb747c4178385
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2023-02-27 02:07:46 +00:00
|
|
|
"###);
|
|
|
|
let stderr = test_env.jj_cmd_failure(&secondary_path, &["st"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: The working copy is stale (not updated since operation 815bb8fcbd7a).
|
|
|
|
Hint: Run `jj workspace update-stale` to update it.
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
|
|
|
|
// It was detected that the working copy is now stale, but clean. So no
|
|
|
|
// divergent commit should be created.
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: a1896a17282f (no description set)
|
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path),
|
|
|
|
@r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
|
2023-02-27 02:07:46 +00:00
|
|
|
│ @ a1896a17282f19089a5cec44358d6609910e0513 secondary@
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c0d4a99ef98ada7da8dc73a778bbb747c4178385
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2023-02-27 02:07:46 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_update_stale_noop() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "update-stale"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Nothing to do (the working copy is not stale).
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&main_path,
|
|
|
|
&["workspace", "update-stale", "--ignore-working-copy"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: This command must be able to update the working copy.
|
|
|
|
Hint: Don't use --ignore-working-copy.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["op", "log", "-Tdescription"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
@ add workspace 'default'
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ initialize repo
|
2023-02-27 02:07:46 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-02-26 11:52:06 +00:00
|
|
|
/// Test "update-stale" in a dirty, but not stale working copy.
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_update_stale_snapshot() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "changed in main\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&main_path, &["new"]);
|
|
|
|
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
|
|
|
|
|
|
|
|
// Record new operation in one workspace.
|
|
|
|
test_env.jj_cmd_success(&main_path, &["new"]);
|
|
|
|
|
|
|
|
// Snapshot the other working copy, which unfortunately results in concurrent
|
|
|
|
// operations, but should be resolved cleanly.
|
|
|
|
std::fs::write(secondary_path.join("file"), "changed in second\n").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Concurrent modification detected, resolving automatically.
|
|
|
|
Nothing to do (the working copy is not stale).
|
|
|
|
"###);
|
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path), @r###"
|
|
|
|
@ 4976dfa88529814c4dd8c06253fbd82d076b79f8 secondary@
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ 8357b22214ba8adb6d2d378fa5b85274f1c7967c default@
|
|
|
|
│ ◉ 1a769966ed69fa7abadbd2d899e2be1025cb04fb
|
2023-02-26 11:52:06 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ b4a6c25e777817db67fdcbd50f1dd3b74b46b5f1
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2023-02-26 11:52:06 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-04-22 04:49:57 +00:00
|
|
|
/// Test forgetting workspaces
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_forget() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents").unwrap();
|
2022-11-05 00:15:35 +00:00
|
|
|
test_env.jj_cmd_success(&main_path, &["new"]);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "forget"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
|
|
|
// When listing workspaces, only the secondary workspace shows up
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-11-05 00:15:35 +00:00
|
|
|
secondary: feda1c4e5ffe (no description set)
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
// `jj status` tells us that there's no working copy here
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["st"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
No working copy
|
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
2022-09-18 21:46:12 +00:00
|
|
|
// The old working copy doesn't get an "@" in the log output
|
2022-04-22 04:49:57 +00:00
|
|
|
// 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###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ feda1c4e5ffe63fb16818ccdd8c21483537e31f2
|
|
|
|
│ ◉ e949be04e93e830fcce23fefac985c1deee52eea
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 123ed18e4c4c0d77428df41112bc02ffc83fb935
|
|
|
|
◉ 0000000000000000000000000000000000000000
|
2022-04-22 04:49:57 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Revision "@" cannot be used
|
|
|
|
let stderr = test_env.jj_cmd_failure(&main_path, &["log", "-r", "@"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Revision "@" doesn't exist
|
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
// Try to add back the workspace
|
|
|
|
// TODO: We should make this just add it back instead of failing
|
|
|
|
let stderr = test_env.jj_cmd_failure(&main_path, &["workspace", "add", "."]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Workspace already exists
|
|
|
|
"###);
|
2022-04-22 04:49:57 +00:00
|
|
|
|
|
|
|
// Forget the secondary workspace
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "forget", "secondary"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
// No workspaces left
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
}
|
|
|
|
|
2023-01-16 02:01:37 +00:00
|
|
|
/// Test context of commit summary template
|
|
|
|
#[test]
|
|
|
|
fn test_list_workspaces_template() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
test_env.add_config(
|
2023-01-26 19:26:18 +00:00
|
|
|
r#"
|
2023-02-28 11:30:57 +00:00
|
|
|
templates.commit_summary = """commit_id.short() ++ " " ++ description.first_line() ++
|
2023-02-14 14:55:30 +00:00
|
|
|
if(current_working_copy, " (current)")"""
|
2023-01-26 19:26:18 +00:00
|
|
|
"#,
|
2023-01-16 02:01:37 +00:00
|
|
|
);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents").unwrap();
|
|
|
|
test_env.jj_cmd_success(&main_path, &["commit", "-m", "initial"]);
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&main_path,
|
|
|
|
&["workspace", "add", "--name", "second", "../secondary"],
|
|
|
|
);
|
|
|
|
|
|
|
|
// "current_working_copy" should point to the workspace we operate on
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-31 09:17:46 +00:00
|
|
|
default: e0e6d5672858 (current)
|
|
|
|
second: f68da2d114f1
|
2023-01-16 02:01:37 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-01-31 09:17:46 +00:00
|
|
|
default: e0e6d5672858
|
|
|
|
second: f68da2d114f1 (current)
|
2023-01-16 02:01:37 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-24 11:46:59 +00:00
|
|
|
/// Test getting the workspace root from primary and secondary workspaces
|
|
|
|
#[test]
|
|
|
|
fn test_workspaces_root() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
$TEST_ENV/main
|
|
|
|
"###);
|
|
|
|
let main_subdir_path = main_path.join("subdir");
|
|
|
|
std::fs::create_dir(&main_subdir_path).unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_subdir_path, &["workspace", "root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
$TEST_ENV/main
|
|
|
|
"###);
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&main_path,
|
|
|
|
&["workspace", "add", "--name", "secondary", "../secondary"],
|
|
|
|
);
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
$TEST_ENV/secondary
|
|
|
|
"###);
|
|
|
|
let secondary_subdir_path = secondary_path.join("subdir");
|
|
|
|
std::fs::create_dir(&secondary_subdir_path).unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_subdir_path, &["workspace", "root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
$TEST_ENV/secondary
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-04-22 04:49:57 +00:00
|
|
|
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
2023-02-28 10:43:14 +00:00
|
|
|
let template = r###"
|
|
|
|
separate(" ",
|
|
|
|
commit_id,
|
|
|
|
working_copies,
|
|
|
|
if(divergent, "(divergent)"),
|
2022-10-19 05:21:25 +00:00
|
|
|
)
|
2023-02-28 10:43:14 +00:00
|
|
|
"###;
|
|
|
|
test_env.jj_cmd_success(cwd, &["log", "-T", template, "-r", "all()"])
|
2022-04-22 04:49:57 +00:00
|
|
|
}
|