2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-05-02 20:03:34 +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.
|
|
|
|
|
2022-05-02 19:58:32 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-07-03 10:04:31 +00:00
|
|
|
use crate::common::TestEnvironment;
|
2022-05-02 20:03:34 +00:00
|
|
|
|
2022-05-02 19:58:32 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_multiple_names() {
|
2022-05-02 19:58:32 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-05-02 19:58:32 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo", "bar"]);
|
2023-07-03 10:04:31 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 2 bookmarks pointing to qpvuntsm 230dd059 bar foo | (empty) (no description set)
|
2024-07-04 23:32:42 +00:00
|
|
|
Hint: Use -r to specify the target revision.
|
2023-07-03 10:04:31 +00:00
|
|
|
"###);
|
2022-05-02 19:58:32 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bar foo 230dd059e1b0
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2022-05-02 19:58:32 +00:00
|
|
|
"###);
|
|
|
|
|
2023-11-10 00:56:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "foo", "bar"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 2 bookmarks to zsuskuln 8bb159bc bar foo | (empty) (no description set)
|
2024-07-04 23:40:53 +00:00
|
|
|
Hint: Use -r to specify the target revision.
|
2023-06-29 02:36:08 +00:00
|
|
|
"###);
|
2022-05-02 19:58:32 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-11-10 00:56:18 +00:00
|
|
|
@ bar foo 8bb159bc30a9
|
2024-07-15 22:20:10 +00:00
|
|
|
○ 230dd059e1b0
|
|
|
|
◆ 000000000000
|
2022-05-02 19:58:32 +00:00
|
|
|
"###);
|
2023-11-09 01:33:57 +00:00
|
|
|
|
2023-11-10 00:56:18 +00:00
|
|
|
let (stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "foo", "bar", "foo"]);
|
2023-11-09 01:33:57 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Deleted 2 bookmarks.
|
2023-11-10 00:56:18 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ 8bb159bc30a9
|
2024-07-15 22:20:10 +00:00
|
|
|
○ 230dd059e1b0
|
|
|
|
◆ 000000000000
|
2023-11-09 01:33:57 +00:00
|
|
|
"###);
|
2024-07-04 23:32:42 +00:00
|
|
|
|
|
|
|
// Hint should be omitted if -r is specified
|
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "-r@-", "foo", "bar"]);
|
2024-07-04 23:32:42 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 2 bookmarks pointing to qpvuntsm 230dd059 bar foo | (empty) (no description set)
|
2024-07-04 23:32:42 +00:00
|
|
|
"###);
|
2024-07-04 23:40:53 +00:00
|
|
|
|
|
|
|
// Create and move with explicit -r
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "-r@", "bar", "baz"]);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 1 bookmarks pointing to zsuskuln 8bb159bc bar baz | (empty) (no description set)
|
|
|
|
Moved 1 bookmarks to zsuskuln 8bb159bc bar baz | (empty) (no description set)
|
|
|
|
Hint: Consider using `jj bookmark move` if your intention was to move existing bookmarks.
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Noop changes should not be included in the stats
|
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "-r@", "foo", "bar", "baz"]);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to zsuskuln 8bb159bc bar baz foo | (empty) (no description set)
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
2022-05-02 19:58:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 02:02:12 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_at_root() {
|
2023-04-04 02:02:12 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-04-04 02:02:12 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "fred", "-r=root()"]);
|
2023-09-03 21:07:15 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-07-04 23:32:42 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 1 bookmarks pointing to zzzzzzzz 00000000 fred | (empty) (no description set)
|
2024-07-04 23:32:42 +00:00
|
|
|
"###);
|
2023-09-03 21:07:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2023-04-04 02:02:12 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-10-10 11:07:06 +00:00
|
|
|
Nothing changed.
|
2024-03-24 06:47:47 +00:00
|
|
|
Warning: Failed to export some branches:
|
2023-12-09 01:23:13 +00:00
|
|
|
fred: Ref cannot point to the root commit in Git
|
2023-04-04 02:02:12 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-11-28 14:17:33 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_empty_name() {
|
2022-11-28 14:17:33 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-11-28 14:17:33 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "create", ""]);
|
2022-11-28 14:17:33 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-03-17 23:14:20 +00:00
|
|
|
error: a value is required for '<NAMES>...' but none was supplied
|
2022-11-28 14:17:33 +00:00
|
|
|
|
2023-03-17 23:14:20 +00:00
|
|
|
For more information, try '--help'.
|
2022-11-28 14:17:33 +00:00
|
|
|
"###);
|
2024-06-20 04:15:50 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "set", ""]);
|
2024-06-20 04:15:50 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
error: a value is required for '<NAMES>...' but none was supplied
|
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
"###);
|
2022-11-28 14:17:33 +00:00
|
|
|
}
|
2023-06-12 01:04:55 +00:00
|
|
|
|
2023-11-09 02:18:53 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_move() {
|
2023-11-09 02:18:53 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-11-09 02:18:53 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-06-14 09:16:23 +00:00
|
|
|
// Set up remote
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
git2::Repository::init_bare(git_repo_path).unwrap();
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "move", "foo"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No such bookmark: foo
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
2023-11-10 00:38:03 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "foo"]);
|
2024-06-21 09:00:04 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 1 bookmarks pointing to qpvuntsm 230dd059 foo | (empty) (no description set)
|
|
|
|
Hint: Consider using `jj bookmark move` if your intention was to move existing bookmarks.
|
2024-06-21 09:00:04 +00:00
|
|
|
"###);
|
2023-11-09 02:18:53 +00:00
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "create", "foo"]);
|
2023-11-09 02:18:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Bookmark already exists: foo
|
|
|
|
Hint: Use `jj bookmark set` to update it.
|
2023-11-09 02:18:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "foo"]);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to mzvwutvl 167f90e7 foo | (empty) (no description set)
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
2023-11-09 02:18:53 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "set", "-r@-", "foo"]);
|
2023-11-09 02:18:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Refusing to move bookmark backwards or sideways: foo
|
2023-11-09 02:18:53 +00:00
|
|
|
Hint: Use --allow-backwards to allow it.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "set", "-r@-", "--allow-backwards", "foo"],
|
2023-11-09 02:18:53 +00:00
|
|
|
);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to qpvuntsm 230dd059 foo | (empty) (no description set)
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
2024-06-16 06:40:53 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "move", "foo"]);
|
2024-07-04 09:44:43 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to mzvwutvl 167f90e7 foo | (empty) (no description set)
|
2024-07-04 09:44:43 +00:00
|
|
|
"###);
|
2024-06-16 06:40:53 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "move", "--to=@-", "foo"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Refusing to move bookmark backwards or sideways: foo
|
2024-06-16 06:40:53 +00:00
|
|
|
Hint: Use --allow-backwards to allow it.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "move", "--to=@-", "--allow-backwards", "foo"],
|
2024-06-16 06:40:53 +00:00
|
|
|
);
|
2024-07-04 09:44:43 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to qpvuntsm 230dd059 foo | (empty) (no description set)
|
2024-07-04 09:44:43 +00:00
|
|
|
"###);
|
2024-06-14 09:16:23 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Delete bookmark locally, but is still tracking remote
|
2024-06-14 09:16:23 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-mcommit"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "push", "-r@-"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "foo"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2024-06-14 09:16:23 +00:00
|
|
|
foo (deleted)
|
2024-06-23 22:20:33 +00:00
|
|
|
@origin: qpvuntsm 1eb845f3 (empty) commit
|
2024-06-14 09:16:23 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Deleted tracking bookmark name should still be allocated
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "create", "foo"]);
|
2024-06-14 09:16:23 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Tracked remote bookmarks exist for deleted bookmark: foo
|
|
|
|
Hint: Use `jj bookmark set` to recreate the local bookmark. Run `jj bookmark untrack 'glob:foo@*'` to disassociate them.
|
2024-06-14 09:16:23 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Restoring local target shouldn't invalidate tracking state
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "foo"]);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to mzvwutvl 66d48752 foo* | (empty) (no description set)
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
foo: mzvwutvl 66d48752 (empty) (no description set)
|
|
|
|
@origin (behind by 1 commits): qpvuntsm 1eb845f3 (empty) commit
|
2024-06-14 09:16:23 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Untracked remote bookmark shouldn't block creation of local bookmark
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "untrack", "foo@origin"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "foo"]);
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo"]);
|
2024-07-04 23:32:42 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Created 1 bookmarks pointing to mzvwutvl 66d48752 foo | (empty) (no description set)
|
2024-07-04 23:32:42 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
foo: mzvwutvl 66d48752 (empty) (no description set)
|
|
|
|
foo@origin: qpvuntsm 1eb845f3 (empty) commit
|
2024-06-14 09:16:23 +00:00
|
|
|
"###);
|
2024-06-16 06:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_move_matching() {
|
2024-06-16 06:40:53 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "a1", "a2"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "-mhead1"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "b1"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "c1"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "-mhead2"]);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ a2781dd9ee37
|
2024-07-15 22:20:10 +00:00
|
|
|
○ c1 f4f38657a3dd
|
|
|
|
○ b1 f652c32197cf
|
|
|
|
│ ○ 6b5e840ea72b
|
|
|
|
│ ○ a1 a2 230dd059e1b0
|
2024-06-16 06:40:53 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// The default could be considered "--from=all() glob:*", but is disabled
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "move"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
error: the following required arguments were not provided:
|
|
|
|
<--from <REVISIONS>|NAMES>
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
Usage: jj bookmark move <--from <REVISIONS>|NAMES>
|
2024-06-16 06:40:53 +00:00
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// No bookmarks pointing to the source revisions
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "move", "--from=none()"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
No bookmarks to update.
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// No matching bookmarks within the source revisions
|
|
|
|
let stderr =
|
|
|
|
test_env.jj_cmd_failure(&repo_path, &["bookmark", "move", "--from=::@", "glob:a?"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No matching bookmarks for patterns: a?
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Noop move
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "move", "--to=a1", "a2"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
No bookmarks to update.
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Move from multiple revisions
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "move", "--from=::@"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 2 bookmarks to vruxwmqv a2781dd9 b1 c1 | (empty) head2
|
|
|
|
Hint: Specify bookmark by name to update just one of the bookmarks.
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ b1 c1 a2781dd9ee37
|
2024-07-15 22:20:10 +00:00
|
|
|
○ f4f38657a3dd
|
|
|
|
○ f652c32197cf
|
|
|
|
│ ○ 6b5e840ea72b
|
|
|
|
│ ○ a1 a2 230dd059e1b0
|
2024-06-16 06:40:53 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Try to move multiple bookmarks, but one of them isn't fast-forward
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "move", "glob:?1"]);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Refusing to move bookmark backwards or sideways: a1
|
2024-06-16 06:40:53 +00:00
|
|
|
Hint: Use --allow-backwards to allow it.
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ a2781dd9ee37
|
2024-07-15 22:20:10 +00:00
|
|
|
○ c1 f4f38657a3dd
|
|
|
|
○ b1 f652c32197cf
|
|
|
|
│ ○ 6b5e840ea72b
|
|
|
|
│ ○ a1 a2 230dd059e1b0
|
2024-06-16 06:40:53 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Select by revision and name
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "move", "--from=::a1+", "--to=a1+", "glob:?1"],
|
2024-06-16 06:40:53 +00:00
|
|
|
);
|
2024-07-04 09:44:43 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to kkmpptxz 6b5e840e a1 | (empty) head1
|
2024-07-04 09:44:43 +00:00
|
|
|
"###);
|
2024-06-16 06:40:53 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ a2781dd9ee37
|
2024-07-15 22:20:10 +00:00
|
|
|
○ c1 f4f38657a3dd
|
|
|
|
○ b1 f652c32197cf
|
|
|
|
│ ○ a1 6b5e840ea72b
|
|
|
|
│ ○ a2 230dd059e1b0
|
2024-06-16 06:40:53 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2024-06-16 06:40:53 +00:00
|
|
|
"###);
|
2023-11-09 02:18:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 05:40:49 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_move_conflicting() {
|
2023-11-10 05:40:49 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-11-10 05:40:49 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let get_log = || {
|
2024-08-21 19:59:15 +00:00
|
|
|
let template = r#"separate(" ", description.first_line(), bookmarks)"#;
|
2023-11-10 05:40:49 +00:00
|
|
|
let (stdout, _stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", template]);
|
|
|
|
stdout
|
|
|
|
};
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-mA0"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-mB0"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-mC0"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "description(A0)", "-mA1"]);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Set up conflicting bookmark.
|
2023-11-10 05:40:49 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "create", "-rdescription(A0)", "foo"],
|
2023-11-10 05:40:49 +00:00
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&[
|
|
|
|
"bookmark",
|
|
|
|
"create",
|
|
|
|
"--at-op=@-",
|
|
|
|
"-rdescription(B0)",
|
|
|
|
"foo",
|
|
|
|
],
|
2023-11-10 05:40:49 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(get_log(), @r###"
|
|
|
|
@ A1
|
2024-07-15 22:20:10 +00:00
|
|
|
○ A0 foo??
|
|
|
|
│ ○ C0
|
2023-11-10 05:40:49 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
│ ○ B0 foo??
|
2023-11-10 05:40:49 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆
|
2023-11-10 05:40:49 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Can't move the bookmark to C0 since it's sibling.
|
2023-11-10 05:40:49 +00:00
|
|
|
let stderr =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_failure(&repo_path, &["bookmark", "set", "-rdescription(C0)", "foo"]);
|
2023-11-10 05:40:49 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Refusing to move bookmark backwards or sideways: foo
|
2023-11-10 05:40:49 +00:00
|
|
|
Hint: Use --allow-backwards to allow it.
|
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Can move the bookmark to A1 since it's descendant of A0. It's not
|
2023-11-10 05:40:49 +00:00
|
|
|
// descendant of B0, though.
|
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "set", "-rdescription(A1)", "foo"]);
|
2024-07-04 23:40:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Moved 1 bookmarks to mzvwutvl 9328d344 foo | (empty) A1
|
2024-07-04 23:40:53 +00:00
|
|
|
"###);
|
2023-11-10 05:40:49 +00:00
|
|
|
insta::assert_snapshot!(get_log(), @r###"
|
|
|
|
@ A1 foo
|
2024-07-15 22:20:10 +00:00
|
|
|
○ A0
|
|
|
|
│ ○ C0
|
2023-11-10 05:40:49 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
│ ○ B0
|
2023-11-10 05:40:49 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆
|
2023-11-10 05:40:49 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-10-18 20:00:10 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_rename() {
|
2023-10-18 20:00:10 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-10-18 20:00:10 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-01-04 14:55:15 +00:00
|
|
|
// Set up remote
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
git2::Repository::init_bare(git_repo_path).unwrap();
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "rename", "bnoexist", "blocal"]);
|
2023-10-18 20:00:10 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No such bookmark: bnoexist
|
2023-10-18 20:00:10 +00:00
|
|
|
"###);
|
|
|
|
|
2024-01-04 14:55:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-0"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "blocal"]);
|
2024-01-04 14:55:15 +00:00
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "rename", "blocal", "blocal1"]);
|
2023-10-18 20:00:10 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-01-04 14:55:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-1"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "bexist"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "rename", "blocal1", "bexist"]);
|
2024-01-04 14:55:15 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: Bookmark already exists: bexist
|
2024-01-04 14:55:15 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-2"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "bremote"]);
|
2024-01-04 14:55:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "push", "-b=bremote"]);
|
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "rename", "bremote", "bremote2"]);
|
2023-10-18 20:00:10 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Tracked remote bookmarks for bookmark bremote were not renamed.
|
|
|
|
Hint: To rename the bookmark on the remote, you can `jj git push --bookmark bremote` first (to delete it on the remote), and then `jj git push --bookmark bremote2`. `jj git push --all` would also be sufficient.
|
2023-10-18 20:00:10 +00:00
|
|
|
"###);
|
2024-06-14 09:16:23 +00:00
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "rename", "bremote2", "bremote"]);
|
2024-06-14 09:16:23 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Tracked remote bookmarks for bookmark bremote exist.
|
|
|
|
Hint: Run `jj bookmark untrack 'glob:bremote@*'` to disassociate them.
|
2024-06-14 09:16:23 +00:00
|
|
|
"###);
|
2023-10-18 20:00:10 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 00:52:49 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_rename_colocated() {
|
2024-07-18 00:52:49 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo", "--colocate"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit-0"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "blocal"]);
|
2024-07-18 00:52:49 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Make sure that git tracking bookmarks don't cause a warning
|
2024-07-18 00:52:49 +00:00
|
|
|
let (_stdout, stderr) =
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "rename", "blocal", "blocal1"]);
|
2024-07-18 00:52:49 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
|
|
|
}
|
|
|
|
|
2022-11-22 23:58:04 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_forget_glob() {
|
2022-11-22 23:58:04 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-11-22 23:58:04 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-1"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "bar-2"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-3"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-4"]);
|
2022-11-22 23:58:04 +00:00
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bar-2 foo-1 foo-3 foo-4 230dd059e1b0
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2022-11-22 23:58:04 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "glob:foo-[1-3]"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Forgot 2 bookmarks.
|
2023-06-29 02:36:08 +00:00
|
|
|
"###);
|
2023-10-19 20:17:58 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "glob:foo-[1-3]"]);
|
2023-10-19 20:17:58 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Forgot 2 bookmarks.
|
2023-10-19 20:17:58 +00:00
|
|
|
"###);
|
2022-11-22 23:58:04 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bar-2 foo-4 230dd059e1b0
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2022-11-22 23:58:04 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Forgetting a bookmark via both explicit name and glob pattern, or with
|
2022-11-22 23:58:04 +00:00
|
|
|
// multiple glob patterns, shouldn't produce an error.
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
2022-11-22 23:58:04 +00:00
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "forget", "foo-4", "glob:foo-*", "glob:foo-*"],
|
2022-11-22 23:58:04 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-06-21 08:41:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Forgot 1 bookmarks.
|
2024-06-21 08:41:53 +00:00
|
|
|
"###);
|
2022-11-22 23:58:04 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bar-2 230dd059e1b0
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2022-11-22 23:58:04 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Malformed glob
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "forget", "glob:foo-[1-3"]);
|
2022-11-22 23:58:04 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-20 11:20:01 +00:00
|
|
|
error: invalid value 'glob:foo-[1-3' for '<NAMES>...': Pattern syntax error near position 4: invalid range pattern
|
2023-10-19 18:49:00 +00:00
|
|
|
|
|
|
|
For more information, try '--help'.
|
2022-11-22 23:58:04 +00:00
|
|
|
"###);
|
2023-06-24 05:52:00 +00:00
|
|
|
|
|
|
|
// We get an error if none of the globs match anything
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "forget", "glob:bar*", "glob:baz*", "glob:boom*"],
|
2023-06-24 05:52:00 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No matching bookmarks for patterns: baz*, boom*
|
2023-06-24 05:52:00 +00:00
|
|
|
"###);
|
2022-11-22 23:58:04 +00:00
|
|
|
}
|
2022-11-28 14:17:33 +00:00
|
|
|
|
2023-06-24 06:27:48 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_delete_glob() {
|
|
|
|
// Set up a git repo with a bookmark and a jj repo that has it as a remote.
|
2023-06-24 06:27:48 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-06-24 06:27:48 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
|
|
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
|
|
let file_oid = git_repo.blob(b"content").unwrap();
|
|
|
|
tree_builder
|
|
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
|
|
.unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(
|
2023-06-24 06:27:48 +00:00
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-1"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "bar-2"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-3"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo-4"]);
|
|
|
|
// Push to create remote-tracking bookmarks
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "push", "--all"]);
|
2023-06-24 06:27:48 +00:00
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
@ bar-2 foo-1 foo-3 foo-4 312a98d6f27b
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "glob:foo-[1-3]"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Deleted 2 bookmarks.
|
2023-06-29 02:36:08 +00:00
|
|
|
"###);
|
2023-10-19 20:17:58 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "glob:foo-[1-3]"]);
|
2023-10-19 20:17:58 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Deleted 2 bookmarks.
|
2023-10-19 20:17:58 +00:00
|
|
|
"###);
|
2023-06-24 06:27:48 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
@ bar-2 foo-1@origin foo-3@origin foo-4 312a98d6f27b
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// We get an error if none of the globs match live bookmarks. Unlike `jj
|
|
|
|
// bookmark forget`, it's not allowed to delete already deleted bookmarks.
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "delete", "glob:foo-[1-3]"]);
|
2023-06-24 06:27:48 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No matching bookmarks for patterns: foo-[1-3]
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Deleting a bookmark via both explicit name and glob pattern, or with
|
2023-06-24 06:27:48 +00:00
|
|
|
// multiple glob patterns, shouldn't produce an error.
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
2023-06-24 06:27:48 +00:00
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "delete", "foo-4", "glob:foo-*", "glob:foo-*"],
|
2023-06-24 06:27:48 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-06-21 08:41:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Deleted 1 bookmarks.
|
2024-06-21 08:41:53 +00:00
|
|
|
"###);
|
2023-06-24 06:27:48 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
@ bar-2 foo-1@origin foo-3@origin foo-4@origin 312a98d6f27b
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// The deleted bookmarks are still there
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
bar-2: qpvuntsm 312a98d6 (empty) commit
|
|
|
|
@origin: qpvuntsm 312a98d6 (empty) commit
|
2023-06-24 06:27:48 +00:00
|
|
|
foo-1 (deleted)
|
2024-06-23 22:20:33 +00:00
|
|
|
@origin: qpvuntsm 312a98d6 (empty) commit
|
2023-06-24 06:27:48 +00:00
|
|
|
foo-3 (deleted)
|
2024-06-23 22:20:33 +00:00
|
|
|
@origin: qpvuntsm 312a98d6 (empty) commit
|
2023-06-24 06:27:48 +00:00
|
|
|
foo-4 (deleted)
|
2024-06-23 22:20:33 +00:00
|
|
|
@origin: qpvuntsm 312a98d6 (empty) commit
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Malformed glob
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "delete", "glob:foo-[1-3"]);
|
2023-10-19 20:17:58 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-20 11:20:01 +00:00
|
|
|
error: invalid value 'glob:foo-[1-3' for '<NAMES>...': Pattern syntax error near position 4: invalid range pattern
|
2023-10-19 20:17:58 +00:00
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Unknown pattern kind
|
2024-08-21 19:59:15 +00:00
|
|
|
let stderr =
|
|
|
|
test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "forget", "whatever:bookmark"]);
|
2023-06-24 06:27:48 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
error: invalid value 'whatever:bookmark' for '<NAMES>...': Invalid string pattern kind "whatever:"
|
2023-10-19 18:49:00 +00:00
|
|
|
|
|
|
|
For more information, try '--help'.
|
2024-07-21 12:44:43 +00:00
|
|
|
Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, or `substring:`
|
2023-06-24 06:27:48 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-09-29 07:40:41 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_delete_export() {
|
2023-09-29 07:40:41 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-09-29 07:40:41 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo"]);
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2023-09-29 07:40:41 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "foo"]);
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "list", "--all-remotes"]);
|
2023-09-29 07:40:41 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
foo (deleted)
|
|
|
|
@git: rlvkpnrz 65b6b74e (empty) (no description set)
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be deleted from the underlying Git repo on the next `jj git export`.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2023-09-29 07:40:41 +00:00
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-09-29 07:40:41 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-06-12 01:04:55 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_forget_export() {
|
2023-06-12 01:04:55 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-06-12 01:04:55 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "foo"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
foo: rlvkpnrz 65b6b74e (empty) (no description set)
|
2023-06-12 01:04:55 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Exporting the bookmark to git creates a local-git tracking bookmark
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2023-06-12 01:04:55 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2023-10-10 11:59:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "foo"]);
|
2023-06-12 01:04:55 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-06-21 08:41:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Forgot 1 bookmarks.
|
2024-06-21 08:41:53 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
// Forgetting a bookmark deletes local and remote-tracking bookmarks including
|
|
|
|
// the corresponding git-tracking bookmark.
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-12 18:59:15 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r=foo", "--no-graph"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Revision "foo" doesn't exist
|
2023-06-12 01:04:55 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// `jj git export` will delete the bookmark from git. In a colocated repo,
|
|
|
|
// this will happen automatically immediately after a `jj bookmark forget`.
|
|
|
|
// This is demonstrated in `test_git_colocated_bookmark_forget` in
|
2023-09-25 11:05:24 +00:00
|
|
|
// test_git_colocated.rs
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2023-06-12 01:04:55 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2023-10-10 11:59:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-12 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 21:49:51 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_forget_fetched_bookmark() {
|
|
|
|
// Much of this test is borrowed from `test_git_fetch_remote_only_bookmark` in
|
2023-06-13 21:49:51 +00:00
|
|
|
// test_git_fetch.rs
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Set up a git repo with a bookmark and a jj repo that has it as a remote.
|
2023-06-13 21:49:51 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2023-12-16 10:00:14 +00:00
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-06-13 21:49:51 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
2023-06-24 06:27:48 +00:00
|
|
|
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
|
2023-06-13 21:49:51 +00:00
|
|
|
let signature =
|
|
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
|
|
let file_oid = git_repo.blob(b"content").unwrap();
|
|
|
|
tree_builder
|
|
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
|
|
.unwrap();
|
|
|
|
let tree_oid = tree_builder.write().unwrap();
|
|
|
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(
|
2023-06-13 21:49:51 +00:00
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
// Create a commit and a bookmark in the git repo
|
2023-06-13 21:49:51 +00:00
|
|
|
let first_git_repo_commit = git_repo
|
|
|
|
.commit(
|
|
|
|
Some("refs/heads/feature1"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
|
|
|
"message",
|
|
|
|
&tree,
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Fetch normally
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
feature1: mzyxwzks 9f01a0e0 message
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: mzyxwzks 9f01a0e0 message
|
2023-06-13 21:49:51 +00:00
|
|
|
"###);
|
|
|
|
|
2023-06-27 22:18:15 +00:00
|
|
|
// TEST 1: with export-import
|
2024-08-21 19:59:15 +00:00
|
|
|
// Forget the bookmark
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "feature1"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-13 21:49:51 +00:00
|
|
|
|
|
|
|
// At this point `jj git export && jj git import` does *not* recreate the
|
2024-08-21 19:59:15 +00:00
|
|
|
// bookmark. This behavior is important in colocated repos, as otherwise a
|
|
|
|
// forgotten bookmark would be immediately resurrected.
|
2023-06-13 21:49:51 +00:00
|
|
|
//
|
2024-08-21 19:59:15 +00:00
|
|
|
// Technically, this is because `jj bookmark forget` preserved
|
2023-06-13 21:49:51 +00:00
|
|
|
// the ref in jj view's `git_refs` tracking the local git repo's remote-tracking
|
2024-08-21 19:59:15 +00:00
|
|
|
// bookmark.
|
2023-06-13 21:49:51 +00:00
|
|
|
// TODO: Show that jj git push is also a no-op
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @"");
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-06-13 21:49:51 +00:00
|
|
|
Nothing changed.
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-13 21:49:51 +00:00
|
|
|
|
2023-06-27 22:18:15 +00:00
|
|
|
// We can fetch feature1 again.
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
|
2023-06-27 22:18:15 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [new] tracked
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
feature1: mzyxwzks 9f01a0e0 message
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: mzyxwzks 9f01a0e0 message
|
2023-06-27 22:18:15 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// TEST 2: No export/import (otherwise the same as test 1)
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "feature1"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-30 02:20:00 +00:00
|
|
|
// Fetch works even without the export-import
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
|
2023-06-30 02:20:00 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [new] tracked
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
feature1: mzyxwzks 9f01a0e0 message
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: mzyxwzks 9f01a0e0 message
|
2023-06-13 21:49:51 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// TEST 3: fetch bookmark that was moved & forgotten
|
2023-06-27 22:18:15 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Move the bookmark in the git repo.
|
2023-06-13 21:49:51 +00:00
|
|
|
git_repo
|
|
|
|
.commit(
|
|
|
|
Some("refs/heads/feature1"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
|
|
|
"another message",
|
|
|
|
&tree,
|
|
|
|
&[&git_repo.find_commit(first_git_repo_commit).unwrap()],
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "feature1"]);
|
2023-06-30 02:20:00 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-06-21 08:41:53 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Forgot 1 bookmarks.
|
2024-06-21 08:41:53 +00:00
|
|
|
"###);
|
2023-06-13 21:49:51 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Fetching a moved bookmark does not create a conflict
|
2023-10-10 11:59:18 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
|
2023-06-13 21:49:51 +00:00
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [new] tracked
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
feature1: ooosovrs 38aefb17 (empty) another message
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: ooosovrs 38aefb17 (empty) another message
|
2023-06-13 21:49:51 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-06-24 04:40:54 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_forget_deleted_or_nonexistent_bookmark() {
|
|
|
|
// Much of this test is borrowed from `test_git_fetch_remote_only_bookmark` in
|
2023-06-24 04:40:54 +00:00
|
|
|
// test_git_fetch.rs
|
|
|
|
|
|
|
|
// ======== Beginning of test setup ========
|
2024-08-21 19:59:15 +00:00
|
|
|
// Set up a git repo with a bookmark and a jj repo that has it as a remote.
|
2023-06-24 04:40:54 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2023-12-16 10:00:14 +00:00
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-06-24 04:40:54 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
2023-06-24 06:27:48 +00:00
|
|
|
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
|
2023-06-24 04:40:54 +00:00
|
|
|
let signature =
|
|
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
|
|
let file_oid = git_repo.blob(b"content").unwrap();
|
|
|
|
tree_builder
|
|
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
|
|
.unwrap();
|
|
|
|
let tree_oid = tree_builder.write().unwrap();
|
|
|
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(
|
2023-06-24 04:40:54 +00:00
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
// Create a commit and a bookmark in the git repo
|
2023-06-24 04:40:54 +00:00
|
|
|
git_repo
|
|
|
|
.commit(
|
|
|
|
Some("refs/heads/feature1"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
|
|
|
"message",
|
|
|
|
&tree,
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Fetch and then delete the bookmark
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "feature1"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-06-24 04:40:54 +00:00
|
|
|
feature1 (deleted)
|
2023-07-11 01:46:38 +00:00
|
|
|
@origin: mzyxwzks 9f01a0e0 message
|
2023-06-24 04:40:54 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// ============ End of test setup ============
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// We can forget a deleted bookmark
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "forget", "feature1"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
2023-06-24 04:40:54 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Can't forget a non-existent bookmark
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["bookmark", "forget", "i_do_not_exist"]);
|
2023-06-24 04:40:54 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No such bookmark: i_do_not_exist
|
2023-06-24 04:40:54 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-10-12 18:29:53 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_track_untrack() {
|
2023-10-12 18:29:53 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-10-12 18:29:53 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
// Set up remote
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
let git_repo = git2::Repository::init(git_repo_path).unwrap();
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
|
|
|
let create_remote_commit = |message: &str, data: &[u8], ref_names: &[&str]| {
|
|
|
|
let signature =
|
|
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0))
|
|
|
|
.unwrap();
|
|
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
|
|
let file_oid = git_repo.blob(data).unwrap();
|
|
|
|
tree_builder
|
|
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
|
|
.unwrap();
|
|
|
|
let tree_oid = tree_builder.write().unwrap();
|
|
|
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
2024-08-21 19:59:15 +00:00
|
|
|
// Create commit and bookmarks in the remote
|
2023-10-12 18:29:53 +00:00
|
|
|
let git_commit_oid = git_repo
|
|
|
|
.commit(None, &signature, &signature, message, &tree, &[])
|
|
|
|
.unwrap();
|
|
|
|
for name in ref_names {
|
|
|
|
git_repo.reference(name, git_commit_oid, true, "").unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Fetch new commit without auto tracking. No local bookmarks should be
|
2023-10-12 18:29:53 +00:00
|
|
|
// created.
|
|
|
|
create_remote_commit(
|
|
|
|
"commit 1",
|
|
|
|
b"content 1",
|
|
|
|
&[
|
|
|
|
"refs/heads/main",
|
|
|
|
"refs/heads/feature1",
|
|
|
|
"refs/heads/feature2",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
test_env.add_config("git.auto-local-branch = false");
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [new] untracked
|
|
|
|
branch: feature2@origin [new] untracked
|
|
|
|
branch: main@origin [new] untracked
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
feature2@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
main@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ feature1@origin feature2@origin main@origin 7b33f6295eda
|
2023-10-12 18:29:53 +00:00
|
|
|
│ @ 230dd059e1b0
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track new bookmark. Local bookmark should be created.
|
2023-10-12 18:29:53 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "track", "feature1@origin", "main@origin"],
|
2023-10-12 18:29:53 +00:00
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1: sptzoqmo 7b33f629 commit 1
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: sptzoqmo 7b33f629 commit 1
|
2023-10-12 18:29:53 +00:00
|
|
|
feature2@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
main: sptzoqmo 7b33f629 commit 1
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: sptzoqmo 7b33f629 commit 1
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track existing bookmark. Local bookmark should result in conflict.
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "feature2"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "track", "feature2@origin"]);
|
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1: sptzoqmo 7b33f629 commit 1
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: sptzoqmo 7b33f629 commit 1
|
2023-10-12 18:29:53 +00:00
|
|
|
feature2 (conflicted):
|
|
|
|
+ qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
+ sptzoqmo 7b33f629 commit 1
|
|
|
|
@origin (behind by 1 commits): sptzoqmo 7b33f629 commit 1
|
|
|
|
main: sptzoqmo 7b33f629 commit 1
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: sptzoqmo 7b33f629 commit 1
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Untrack existing and locally-deleted bookmarks. Branch targets should be
|
2023-10-12 18:29:53 +00:00
|
|
|
// unchanged
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "delete", "feature2"]);
|
2023-10-12 18:29:53 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "untrack", "feature1@origin", "feature2@origin"],
|
2023-10-12 18:29:53 +00:00
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1: sptzoqmo 7b33f629 commit 1
|
|
|
|
feature1@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
feature2@origin: sptzoqmo 7b33f629 commit 1
|
|
|
|
main: sptzoqmo 7b33f629 commit 1
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: sptzoqmo 7b33f629 commit 1
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ feature1 feature1@origin feature2@origin main 7b33f6295eda
|
2023-10-12 18:29:53 +00:00
|
|
|
│ @ 230dd059e1b0
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Fetch new commit. Only tracking bookmark "main" should be merged.
|
2023-10-12 18:29:53 +00:00
|
|
|
create_remote_commit(
|
|
|
|
"commit 2",
|
|
|
|
b"content 2",
|
|
|
|
&[
|
|
|
|
"refs/heads/main",
|
|
|
|
"refs/heads/feature1",
|
|
|
|
"refs/heads/feature2",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [updated] untracked
|
|
|
|
branch: feature2@origin [updated] untracked
|
|
|
|
branch: main@origin [updated] tracked
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1: sptzoqmo 7b33f629 commit 1
|
|
|
|
feature1@origin: mmqqkyyt 40dabdaf commit 2
|
|
|
|
feature2@origin: mmqqkyyt 40dabdaf commit 2
|
|
|
|
main: mmqqkyyt 40dabdaf commit 2
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: mmqqkyyt 40dabdaf commit 2
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ feature1@origin feature2@origin main 40dabdaf4abe
|
|
|
|
│ ○ feature1 7b33f6295eda
|
2023-10-12 18:29:53 +00:00
|
|
|
├─╯
|
|
|
|
│ @ 230dd059e1b0
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Fetch new commit with auto tracking. Tracking bookmark "main" and new
|
|
|
|
// bookmark "feature3" should be merged.
|
2023-10-12 18:29:53 +00:00
|
|
|
create_remote_commit(
|
|
|
|
"commit 3",
|
|
|
|
b"content 3",
|
|
|
|
&[
|
|
|
|
"refs/heads/main",
|
|
|
|
"refs/heads/feature1",
|
|
|
|
"refs/heads/feature2",
|
|
|
|
"refs/heads/feature3",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-02-13 22:17:05 +00:00
|
|
|
branch: feature1@origin [updated] untracked
|
|
|
|
branch: feature2@origin [updated] untracked
|
|
|
|
branch: feature3@origin [new] tracked
|
|
|
|
branch: main@origin [updated] tracked
|
2023-10-12 18:29:53 +00:00
|
|
|
Abandoned 1 commits that are no longer reachable.
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-12 18:29:53 +00:00
|
|
|
feature1: sptzoqmo 7b33f629 commit 1
|
|
|
|
feature1@origin: wwnpyzpo 3f0f86fa commit 3
|
|
|
|
feature2@origin: wwnpyzpo 3f0f86fa commit 3
|
|
|
|
feature3: wwnpyzpo 3f0f86fa commit 3
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: wwnpyzpo 3f0f86fa commit 3
|
2023-10-12 18:29:53 +00:00
|
|
|
main: wwnpyzpo 3f0f86fa commit 3
|
2023-10-18 06:12:17 +00:00
|
|
|
@origin: wwnpyzpo 3f0f86fa commit 3
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ feature1@origin feature2@origin feature3 main 3f0f86fa0e57
|
|
|
|
│ ○ feature1 7b33f6295eda
|
2023-10-12 18:29:53 +00:00
|
|
|
├─╯
|
|
|
|
│ @ 230dd059e1b0
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2024-05-14 16:20:37 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_track_conflict() {
|
2024-05-14 16:20:37 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-05-14 16:20:37 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
git2::Repository::init_bare(git_repo_path).unwrap();
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "main"]);
|
2024-05-14 16:20:37 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "a"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "push", "-b", "main"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "untrack", "main@origin"]);
|
2024-05-14 16:20:37 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["describe", "-m", "b", "-r", "main", "--ignore-immutable"],
|
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "track", "main@origin"]);
|
2024-05-14 16:20:37 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Started tracking 1 remote bookmarks.
|
2024-06-23 22:20:33 +00:00
|
|
|
main (conflicted):
|
|
|
|
+ qpvuntsm e802c4f8 (empty) b
|
|
|
|
+ qpvuntsm hidden 427890ea (empty) a
|
|
|
|
@origin (behind by 1 commits): qpvuntsm hidden 427890ea (empty) a
|
|
|
|
"###);
|
2024-05-14 16:20:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 18:29:53 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_track_untrack_patterns() {
|
2023-10-12 18:29:53 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-10-12 18:29:53 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
// Set up remote
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
let git_repo = git2::Repository::init(git_repo_path).unwrap();
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create remote commit
|
|
|
|
let signature =
|
|
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
|
|
let file_oid = git_repo.blob(b"content").unwrap();
|
|
|
|
tree_builder
|
|
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
|
|
.unwrap();
|
|
|
|
let tree_oid = tree_builder.write().unwrap();
|
|
|
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
2024-08-21 19:59:15 +00:00
|
|
|
// Create commit and bookmarks in the remote
|
2023-10-12 18:29:53 +00:00
|
|
|
let git_commit_oid = git_repo
|
|
|
|
.commit(None, &signature, &signature, "commit", &tree, &[])
|
|
|
|
.unwrap();
|
|
|
|
for name in ["refs/heads/feature1", "refs/heads/feature2"] {
|
|
|
|
git_repo.reference(name, git_commit_oid, true, "").unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch new commit without auto tracking
|
|
|
|
test_env.add_config("git.auto-local-branch = false");
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
|
2024-02-13 22:17:05 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
branch: feature1@origin [new] untracked
|
|
|
|
branch: feature2@origin [new] untracked
|
|
|
|
"###);
|
2023-10-12 18:29:53 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track local bookmark
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "main"]);
|
2023-10-12 18:29:53 +00:00
|
|
|
insta::assert_snapshot!(
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_cli_error(&repo_path, &["bookmark", "track", "main"]), @r###"
|
|
|
|
error: invalid value 'main' for '<BRANCH@REMOTE>...': remote bookmark must be specified in bookmark@remote form
|
2023-10-12 18:29:53 +00:00
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track/untrack unknown bookmark
|
2023-10-12 18:29:53 +00:00
|
|
|
insta::assert_snapshot!(
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_failure(&repo_path, &["bookmark", "track", "main@origin"]), @r###"
|
|
|
|
Error: No such remote bookmark: main@origin
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_failure(&repo_path, &["bookmark", "untrack", "main@origin"]), @r###"
|
|
|
|
Error: No such remote bookmark: main@origin
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
2023-10-19 21:40:58 +00:00
|
|
|
insta::assert_snapshot!(
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_failure(&repo_path, &["bookmark", "track", "glob:maine@*"]), @r###"
|
|
|
|
Error: No matching remote bookmarks for patterns: maine@*
|
2023-10-19 21:40:58 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "untrack", "main@origin", "glob:main@o*"],
|
2023-10-19 21:40:58 +00:00
|
|
|
), @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Error: No matching remote bookmarks for patterns: main@origin, main@o*
|
2023-10-19 21:40:58 +00:00
|
|
|
"###);
|
2023-10-12 18:29:53 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track already tracked bookmark
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "track", "feature1@origin"]);
|
|
|
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "track", "feature1@origin"]);
|
2023-10-20 04:14:09 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Remote bookmark already tracked: feature1@origin
|
2023-10-20 04:14:09 +00:00
|
|
|
Nothing changed.
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Untrack non-tracking bookmark
|
|
|
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "untrack", "feature2@origin"]);
|
2023-10-20 04:14:09 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Remote bookmark not tracked yet: feature2@origin
|
2023-10-20 04:14:09 +00:00
|
|
|
Nothing changed.
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Untrack Git-tracking bookmark
|
2023-10-12 18:29:53 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "untrack", "main@git"]);
|
2023-10-20 04:14:09 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Git-tracking bookmark cannot be untracked: main@git
|
2023-10-20 04:14:09 +00:00
|
|
|
Nothing changed.
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-20 04:14:09 +00:00
|
|
|
feature1: omvolwpu 1336caed commit
|
|
|
|
@git: omvolwpu 1336caed commit
|
|
|
|
@origin: omvolwpu 1336caed commit
|
|
|
|
feature2@origin: omvolwpu 1336caed commit
|
|
|
|
main: qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
2023-10-12 18:29:53 +00:00
|
|
|
"###);
|
2023-10-19 21:40:58 +00:00
|
|
|
|
|
|
|
// Untrack by pattern
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["bookmark", "untrack", "glob:*@*"]);
|
2023-10-19 21:40:58 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Warning: Git-tracking bookmark cannot be untracked: feature1@git
|
|
|
|
Warning: Remote bookmark not tracked yet: feature2@origin
|
|
|
|
Warning: Git-tracking bookmark cannot be untracked: main@git
|
|
|
|
Stopped tracking 1 remote bookmarks.
|
2023-10-19 21:40:58 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-19 21:40:58 +00:00
|
|
|
feature1: omvolwpu 1336caed commit
|
|
|
|
@git: omvolwpu 1336caed commit
|
|
|
|
feature1@origin: omvolwpu 1336caed commit
|
|
|
|
feature2@origin: omvolwpu 1336caed commit
|
|
|
|
main: qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Track by pattern
|
2024-08-21 19:59:15 +00:00
|
|
|
let (_, stderr) =
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "track", "glob:feature?@origin"]);
|
2023-10-20 22:09:29 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Started tracking 2 remote bookmarks.
|
2023-10-20 22:09:29 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2023-10-19 21:40:58 +00:00
|
|
|
feature1: omvolwpu 1336caed commit
|
|
|
|
@git: omvolwpu 1336caed commit
|
|
|
|
@origin: omvolwpu 1336caed commit
|
|
|
|
feature2: omvolwpu 1336caed commit
|
|
|
|
@origin: omvolwpu 1336caed commit
|
|
|
|
main: qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
"###);
|
2023-10-12 18:29:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 06:12:17 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_list() {
|
2023-10-18 06:12:17 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2023-12-16 10:00:14 +00:00
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
2023-10-18 06:12:17 +00:00
|
|
|
|
|
|
|
// Initialize remote refs
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "remote"]);
|
2023-10-18 06:12:17 +00:00
|
|
|
let remote_path = test_env.env_root().join("remote");
|
2024-08-21 19:59:15 +00:00
|
|
|
for bookmark in [
|
2023-10-18 06:12:17 +00:00
|
|
|
"remote-sync",
|
|
|
|
"remote-unsync",
|
|
|
|
"remote-untrack",
|
|
|
|
"remote-delete",
|
|
|
|
] {
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new", "root()", "-m", bookmark]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["bookmark", "create", bookmark]);
|
2023-10-18 06:12:17 +00:00
|
|
|
}
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["git", "export"]);
|
|
|
|
|
|
|
|
// Initialize local refs
|
|
|
|
let mut remote_git_path = remote_path;
|
|
|
|
remote_git_path.extend([".jj", "repo", "store", "git"]);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
test_env.env_root(),
|
|
|
|
&["git", "clone", remote_git_path.to_str().unwrap(), "local"],
|
|
|
|
);
|
|
|
|
let local_path = test_env.env_root().join("local");
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["new", "root()", "-m", "local-only"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "create", "local-only"]);
|
2023-10-18 06:12:17 +00:00
|
|
|
|
|
|
|
// Mutate refs in local repository
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "delete", "remote-delete"]);
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "delete", "remote-untrack"]);
|
2023-10-18 06:12:17 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "untrack", "remote-untrack@origin"],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
|
|
|
&["bookmark", "set", "--allow-backwards", "remote-unsync"],
|
2023-10-18 06:12:17 +00:00
|
|
|
);
|
|
|
|
|
2023-10-18 06:56:02 +00:00
|
|
|
// Synchronized tracking remotes and non-tracking remotes aren't listed by
|
|
|
|
// default
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-10-18 06:12:17 +00:00
|
|
|
local-only: wqnwkozp 4e887f78 (empty) local-only
|
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: mnmymoky 203e60eb (empty) remote-delete
|
|
|
|
remote-sync: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
remote-unsync: wqnwkozp 4e887f78 (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2023-10-18 06:12:17 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list", "--all-remotes"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-10-18 06:12:17 +00:00
|
|
|
local-only: wqnwkozp 4e887f78 (empty) local-only
|
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: mnmymoky 203e60eb (empty) remote-delete
|
|
|
|
remote-sync: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
@origin: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
remote-unsync: wqnwkozp 4e887f78 (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
remote-untrack@origin: vmortlor 71a16b05 (empty) remote-untrack
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2024-04-30 06:00:07 +00:00
|
|
|
|
|
|
|
let template = r#"
|
|
|
|
concat(
|
|
|
|
"[" ++ name ++ if(remote, "@" ++ remote) ++ "]\n",
|
|
|
|
separate(" ", "present:", present) ++ "\n",
|
|
|
|
separate(" ", "conflict:", conflict) ++ "\n",
|
|
|
|
separate(" ", "normal_target:", normal_target.description().first_line()) ++ "\n",
|
|
|
|
separate(" ", "removed_targets:", removed_targets.map(|c| c.description().first_line())) ++ "\n",
|
|
|
|
separate(" ", "added_targets:", added_targets.map(|c| c.description().first_line())) ++ "\n",
|
|
|
|
separate(" ", "tracked:", tracked) ++ "\n",
|
|
|
|
separate(" ", "tracking_present:", tracking_present) ++ "\n",
|
|
|
|
separate(" ", "tracking_ahead_count:", tracking_ahead_count.lower()) ++ "\n",
|
|
|
|
separate(" ", "tracking_behind_count:", tracking_behind_count.lower()) ++ "\n",
|
|
|
|
)
|
|
|
|
"#;
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "list", "--all-remotes", "-T", template],
|
2024-05-09 10:45:11 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-04-30 06:00:07 +00:00
|
|
|
[local-only]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: local-only
|
|
|
|
removed_targets:
|
|
|
|
added_targets: local-only
|
|
|
|
tracked: false
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: <Error: Not a tracked remote ref>
|
|
|
|
tracking_behind_count: <Error: Not a tracked remote ref>
|
|
|
|
[remote-delete]
|
|
|
|
present: false
|
|
|
|
conflict: false
|
|
|
|
normal_target: <Error: No Commit available>
|
|
|
|
removed_targets:
|
|
|
|
added_targets:
|
|
|
|
tracked: false
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: <Error: Not a tracked remote ref>
|
|
|
|
tracking_behind_count: <Error: Not a tracked remote ref>
|
|
|
|
[remote-delete@origin]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: remote-delete
|
|
|
|
removed_targets:
|
|
|
|
added_targets: remote-delete
|
|
|
|
tracked: true
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: 2
|
|
|
|
tracking_behind_count: 0
|
|
|
|
[remote-sync]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: remote-sync
|
|
|
|
removed_targets:
|
|
|
|
added_targets: remote-sync
|
|
|
|
tracked: false
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: <Error: Not a tracked remote ref>
|
|
|
|
tracking_behind_count: <Error: Not a tracked remote ref>
|
|
|
|
[remote-sync@origin]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: remote-sync
|
|
|
|
removed_targets:
|
|
|
|
added_targets: remote-sync
|
|
|
|
tracked: true
|
|
|
|
tracking_present: true
|
|
|
|
tracking_ahead_count: 0
|
|
|
|
tracking_behind_count: 0
|
|
|
|
[remote-unsync]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: local-only
|
|
|
|
removed_targets:
|
|
|
|
added_targets: local-only
|
|
|
|
tracked: false
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: <Error: Not a tracked remote ref>
|
|
|
|
tracking_behind_count: <Error: Not a tracked remote ref>
|
|
|
|
[remote-unsync@origin]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: remote-unsync
|
|
|
|
removed_targets:
|
|
|
|
added_targets: remote-unsync
|
|
|
|
tracked: true
|
|
|
|
tracking_present: true
|
|
|
|
tracking_ahead_count: 1
|
|
|
|
tracking_behind_count: 1
|
|
|
|
[remote-untrack@origin]
|
|
|
|
present: true
|
|
|
|
conflict: false
|
|
|
|
normal_target: remote-untrack
|
|
|
|
removed_targets:
|
|
|
|
added_targets: remote-untrack
|
|
|
|
tracked: false
|
|
|
|
tracking_present: false
|
|
|
|
tracking_ahead_count: <Error: Not a tracked remote ref>
|
|
|
|
tracking_behind_count: <Error: Not a tracked remote ref>
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2023-10-18 06:12:17 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 02:53:01 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_list_filtered() {
|
2023-06-28 02:53:01 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2023-12-16 10:00:14 +00:00
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
cli: make set of immutable commits configurable
This adds a new `revset-aliases.immutable_heads()s` config for
defining the set of immutable commits. The set is defined as the
configured revset, as well as its ancestors, and the root commit
commit (even if the configured set is empty).
This patch also adds enforcement of the config where we already had
checks preventing rewrite of the root commit. The working-copy commit
is implicitly assumed to be writable in most cases. Specifically, we
won't prevent amending the working copy even if the user includes it
in the config but we do prevent `jj edit @` in that case. That seems
good enough to me. Maybe we should emit a warning when the working
copy is in the set of immutable commits.
Maybe we should add support for something more like [Mercurial's
phases](https://wiki.mercurial-scm.org/Phases), which is propagated on
push and pull. There's already some affordance for that in the view
object's `public_heads` field. However, this is simpler, especially
since we can't propagate the phase to Git remotes, and seems like a
good start. Also, it lets you say that commits authored by other users
are immutable, for example.
For now, the functionality is in the CLI library. I'm not sure if we
want to move it into the library crate. I'm leaning towards letting
library users do whatever they want without being restricted by
immutable commits. I do think we should move the functionality into a
future `ui-lib` or `ui-util` crate. That crate would have most of the
functionality in the current `cli_util` module (but in a
non-CLI-specific form).
2023-09-02 02:12:01 +00:00
|
|
|
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
|
2023-06-28 02:53:01 +00:00
|
|
|
|
|
|
|
// Initialize remote refs
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "remote"]);
|
2023-06-28 02:53:01 +00:00
|
|
|
let remote_path = test_env.env_root().join("remote");
|
2024-08-21 19:59:15 +00:00
|
|
|
for bookmark in ["remote-keep", "remote-delete", "remote-rewrite"] {
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new", "root()", "-m", bookmark]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["bookmark", "create", bookmark]);
|
2023-06-28 02:53:01 +00:00
|
|
|
}
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["git", "export"]);
|
2023-06-28 02:53:01 +00:00
|
|
|
|
|
|
|
// Initialize local refs
|
|
|
|
let mut remote_git_path = remote_path;
|
|
|
|
remote_git_path.extend([".jj", "repo", "store", "git"]);
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(
|
2023-06-28 02:53:01 +00:00
|
|
|
test_env.env_root(),
|
|
|
|
&["git", "clone", remote_git_path.to_str().unwrap(), "local"],
|
|
|
|
);
|
|
|
|
let local_path = test_env.env_root().join("local");
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["new", "root()", "-m", "local-keep"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "create", "local-keep"]);
|
2023-06-28 02:53:01 +00:00
|
|
|
|
|
|
|
// Mutate refs in local repository
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "delete", "remote-delete"]);
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["describe", "-mrewritten", "remote-rewrite"]);
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let template = r#"separate(" ", commit_id.short(), bookmarks, if(hidden, "(hidden)"))"#;
|
2023-06-28 02:53:01 +00:00
|
|
|
insta::assert_snapshot!(
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["log", "-r::(bookmarks() | remote_bookmarks())", "-T", template],
|
2023-06-28 02:53:01 +00:00
|
|
|
),
|
|
|
|
@r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
○ e31634b64294 remote-rewrite*
|
2023-06-28 02:53:01 +00:00
|
|
|
│ @ c7b4c09cd77c local-keep
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
│ ○ 3e9a5af6ef15 remote-rewrite@origin (hidden)
|
2023-06-28 02:53:01 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
│ ○ dad5f298ca57 remote-delete@origin
|
2023-06-28 02:53:01 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
│ ○ 911e912015fb remote-keep
|
index: import commits in chronological order
This basically means that heads in a filtered graph appear in reverse
chronological order. Before, "jj log -r 'tags()'" in linux-stable repo would
look randomly sorted once you ran "jj debug reindex" in it.
With this change, indexing is more like breadth-first search, and BFS is
known to be bad at rendering nice graph (because branches run in parallel.)
However, we have a post process to group topological branches, so we don't
have this problem. For serialization formats like Mercurial's revlog iirc,
BFS leads to bad compression ratio, but our index isn't that kind of data.
Reindexing gets slightly slower, but I think this is negligible.
(in Git repository)
% hyperfine --warmup 3 --runs 10 "jj debug reindex --ignore-working-copy"
(original)
Time (mean ± σ): 1.521 s ± 0.027 s [User: 1.307 s, System: 0.211 s]
Range (min … max): 1.486 s … 1.573 s 10 runs
(new)
Time (mean ± σ): 1.568 s ± 0.027 s [User: 1.368 s, System: 0.197 s]
Range (min … max): 1.531 s … 1.625 s 10 runs
Another idea is to sort heads chronologically and run DFS-based topological
sorting. It's ad-hoc, but worked surprisingly well for my local repositories.
For repositories with lots of long-running branches, this commit will provide
more predictable result than DFS-based one.
2023-08-12 10:32:05 +00:00
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
◆ 000000000000
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// All bookmarks are listed by default.
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
2023-06-28 02:53:01 +00:00
|
|
|
remote-delete (deleted)
|
2023-07-11 01:46:38 +00:00
|
|
|
@origin: yxusvupt dad5f298 (empty) remote-delete
|
|
|
|
remote-keep: nlwprzpn 911e9120 (empty) remote-keep
|
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
2023-10-24 01:43:12 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2023-11-01 03:01:17 +00:00
|
|
|
let query =
|
2024-08-21 19:59:15 +00:00
|
|
|
|args: &[&str]| test_env.jj_cmd_ok(&local_path, &[&["bookmark", "list"], args].concat());
|
|
|
|
let query_error = |args: &[&str]| {
|
|
|
|
test_env.jj_cmd_failure(&local_path, &[&["bookmark", "list"], args].concat())
|
|
|
|
};
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// "all()" doesn't include deleted bookmarks since they have no local targets.
|
|
|
|
// So "all()" is identical to "bookmarks()".
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["-rall()"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
|
|
|
remote-keep: nlwprzpn 911e9120 (empty) remote-keep
|
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
2023-10-24 01:43:12 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Exclude remote-only bookmarks. "remote-rewrite@origin" is included since
|
2023-06-28 02:53:01 +00:00
|
|
|
// local "remote-rewrite" target matches.
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = query(&["-rbookmarks()"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
|
|
|
remote-keep: nlwprzpn 911e9120 (empty) remote-keep
|
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
2023-10-24 01:43:12 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Select bookmarks by name.
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["remote-rewrite"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-11-01 03:01:17 +00:00
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = query(&["-rbookmarks(remote-rewrite)"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-07-11 01:46:38 +00:00
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
2023-10-24 01:43:12 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-06-28 02:53:01 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Select bookmarks by name, combined with --all-remotes
|
2024-03-28 18:13:33 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["git", "export"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["--all-remotes", "remote-rewrite"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-04-02 06:53:20 +00:00
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@git: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = query(&["--all-remotes", "-rbookmarks(remote-rewrite)"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-03-28 18:13:33 +00:00
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@git: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-03-28 18:13:33 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Can select deleted bookmark by name pattern, but not by revset.
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["remote-delete"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-11-01 03:01:17 +00:00
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: yxusvupt dad5f298 (empty) remote-delete
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = query(&["-rbookmarks(remote-delete)"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-07-02 00:59:34 +00:00
|
|
|
"###);
|
2023-11-01 03:01:17 +00:00
|
|
|
insta::assert_snapshot!(query_error(&["-rremote-delete"]), @r###"
|
2023-07-02 00:59:34 +00:00
|
|
|
Error: Revision "remote-delete" doesn't exist
|
2023-07-02 04:57:44 +00:00
|
|
|
Hint: Did you mean "remote-delete@origin", "remote-keep", "remote-rewrite", "remote-rewrite@origin"?
|
2023-06-28 02:53:01 +00:00
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-11-01 03:01:17 +00:00
|
|
|
|
|
|
|
// Name patterns are OR-ed.
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["glob:*-keep", "remote-delete"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-11-01 03:01:17 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: yxusvupt dad5f298 (empty) remote-delete
|
|
|
|
remote-keep: nlwprzpn 911e9120 (empty) remote-keep
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2023-11-01 03:01:17 +00:00
|
|
|
|
|
|
|
// Unmatched name pattern shouldn't be an error. A warning can be added later.
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = query(&["local-keep", "glob:push-*"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-11-01 03:01:17 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-11-01 03:01:17 +00:00
|
|
|
|
|
|
|
// Name pattern and revset are OR-ed.
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = query(&["local-keep", "-rbookmarks(remote-rewrite)"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-11-01 03:01:17 +00:00
|
|
|
local-keep: kpqxywon c7b4c09c (empty) local-keep
|
|
|
|
remote-rewrite: xyxluytn e31634b6 (empty) rewritten
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): xyxluytn hidden 3e9a5af6 (empty) remote-rewrite
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2023-06-28 02:53:01 +00:00
|
|
|
}
|
|
|
|
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_list_much_remote_divergence() {
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
|
|
|
|
|
|
|
// Initialize remote refs
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "remote"]);
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
let remote_path = test_env.env_root().join("remote");
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new", "root()", "-m", "remote-unsync"]);
|
|
|
|
for _ in 0..15 {
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new", "-m", "remote-unsync"]);
|
|
|
|
}
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&remote_path, &["bookmark", "create", "remote-unsync"]);
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["git", "export"]);
|
|
|
|
|
|
|
|
// Initialize local refs
|
|
|
|
let mut remote_git_path = remote_path;
|
|
|
|
remote_git_path.extend([".jj", "repo", "store", "git"]);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
test_env.env_root(),
|
|
|
|
&["git", "clone", remote_git_path.to_str().unwrap(), "local"],
|
|
|
|
);
|
|
|
|
let local_path = test_env.env_root().join("local");
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["new", "root()", "-m", "local-only"]);
|
|
|
|
for _ in 0..15 {
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["new", "-m", "local-only"]);
|
|
|
|
}
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "create", "local-only"]);
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
|
|
|
|
// Mutate refs in local repository
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "set", "--allow-backwards", "remote-unsync"],
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
local-only: zkyosouw 4ab3f751 (empty) local-only
|
|
|
|
remote-unsync: zkyosouw 4ab3f751 (empty) local-only
|
|
|
|
@origin (ahead by at least 10 commits, behind by at least 10 commits): lxyktnks 19582022 (empty) remote-unsync
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).
Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.
Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)
"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-16 22:12:02 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 18:27:50 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_list_tracked() {
|
2024-02-21 18:27:50 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.add_config("git.auto-local-branch = true");
|
|
|
|
|
|
|
|
// Initialize remote refs
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "remote"]);
|
2024-02-21 18:27:50 +00:00
|
|
|
let remote_path = test_env.env_root().join("remote");
|
2024-08-21 19:59:15 +00:00
|
|
|
for bookmark in [
|
2024-02-21 18:27:50 +00:00
|
|
|
"remote-sync",
|
|
|
|
"remote-unsync",
|
|
|
|
"remote-untrack",
|
|
|
|
"remote-delete",
|
|
|
|
] {
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new", "root()", "-m", bookmark]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["bookmark", "create", bookmark]);
|
2024-02-21 18:27:50 +00:00
|
|
|
}
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&remote_path, &["git", "export"]);
|
|
|
|
|
|
|
|
// Initialize local refs
|
|
|
|
let mut remote_git_path = test_env.env_root().join("remote");
|
|
|
|
remote_git_path.extend([".jj", "repo", "store", "git"]);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
test_env.env_root(),
|
|
|
|
&[
|
|
|
|
"git",
|
|
|
|
"clone",
|
|
|
|
"--colocate",
|
|
|
|
remote_git_path.to_str().unwrap(),
|
|
|
|
"local",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "upstream"]);
|
2024-02-21 18:27:50 +00:00
|
|
|
|
|
|
|
// Initialize a second remote
|
|
|
|
let mut upstream_git_path = test_env.env_root().join("upstream");
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&upstream_git_path,
|
|
|
|
&["new", "root()", "-m", "upstream-sync"],
|
|
|
|
);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&upstream_git_path, &["bookmark", "create", "upstream-sync"]);
|
2024-02-21 18:27:50 +00:00
|
|
|
test_env.jj_cmd_ok(&upstream_git_path, &["new"]);
|
|
|
|
test_env.jj_cmd_ok(&upstream_git_path, &["git", "export"]);
|
|
|
|
|
|
|
|
upstream_git_path.extend([".jj", "repo", "store", "git"]);
|
|
|
|
|
|
|
|
let local_path = test_env.env_root().join("local");
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
|
|
|
&[
|
|
|
|
"git",
|
|
|
|
"remote",
|
|
|
|
"add",
|
|
|
|
"upstream",
|
|
|
|
upstream_git_path.to_str().unwrap(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["git", "fetch", "--all-remotes"]);
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["new", "root()", "-m", "local-only"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "create", "local-only"]);
|
2024-02-21 18:27:50 +00:00
|
|
|
|
|
|
|
// Mutate refs in local repository
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "delete", "remote-delete"]);
|
|
|
|
test_env.jj_cmd_ok(&local_path, &["bookmark", "delete", "remote-untrack"]);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
|
|
|
&["bookmark", "untrack", "remote-untrack@origin"],
|
|
|
|
);
|
2024-02-21 18:27:50 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
|
|
|
&[
|
|
|
|
"git",
|
|
|
|
"push",
|
|
|
|
"--remote",
|
|
|
|
"upstream",
|
2024-08-21 19:59:15 +00:00
|
|
|
"--bookmark",
|
2024-02-21 18:27:50 +00:00
|
|
|
"remote-unsync",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "set", "--allow-backwards", "remote-unsync"],
|
2024-02-21 18:27:50 +00:00
|
|
|
);
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list", "--all-remotes"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-02-21 18:27:50 +00:00
|
|
|
local-only: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@git: nmzmmopx e1da745b (empty) local-only
|
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: mnmymoky 203e60eb (empty) remote-delete
|
|
|
|
remote-sync: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
@git: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
@origin: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
remote-unsync: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@git: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
@upstream (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
remote-untrack@origin: vmortlor 71a16b05 (empty) remote-untrack
|
|
|
|
upstream-sync: lolpmnqw 32fa6da0 (empty) upstream-sync
|
|
|
|
@git: lolpmnqw 32fa6da0 (empty) upstream-sync
|
|
|
|
@upstream: lolpmnqw 32fa6da0 (empty) upstream-sync
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2024-02-21 18:27:50 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&local_path, &["bookmark", "list", "--tracked"]);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-02-21 18:27:50 +00:00
|
|
|
remote-delete (deleted)
|
|
|
|
@origin: mnmymoky 203e60eb (empty) remote-delete
|
|
|
|
remote-sync: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
@origin: zwtyzrop c761c7ea (empty) remote-sync
|
|
|
|
remote-unsync: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
@upstream (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
upstream-sync: lolpmnqw 32fa6da0 (empty) upstream-sync
|
|
|
|
@upstream: lolpmnqw 32fa6da0 (empty) upstream-sync
|
|
|
|
"###
|
|
|
|
);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-08-21 19:59:15 +00:00
|
|
|
Hint: Bookmarkes marked as deleted will be *deleted permanently* on the remote on the next `jj git push`. Use `jj bookmark forget` to prevent this.
|
2024-05-09 10:45:11 +00:00
|
|
|
"###);
|
2024-02-21 18:27:50 +00:00
|
|
|
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "list", "--tracked", "remote-unsync"],
|
2024-05-09 10:45:11 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-02-21 18:27:50 +00:00
|
|
|
remote-unsync: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
@upstream (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-02-21 18:27:50 +00:00
|
|
|
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "list", "--tracked", "remote-untrack"],
|
2024-05-09 10:45:11 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-02-21 18:27:50 +00:00
|
|
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "untrack", "remote-unsync@upstream"],
|
2024-02-21 18:27:50 +00:00
|
|
|
);
|
|
|
|
|
2024-05-09 10:45:11 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
&local_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "list", "--tracked", "remote-unsync"],
|
2024-05-09 10:45:11 +00:00
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-02-21 18:27:50 +00:00
|
|
|
remote-unsync: nmzmmopx e1da745b (empty) local-only
|
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync
|
|
|
|
"###);
|
2024-05-09 10:45:11 +00:00
|
|
|
insta::assert_snapshot!(stderr, @"");
|
2024-02-21 18:27:50 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 12:43:43 +00:00
|
|
|
#[test]
|
2024-08-21 19:59:15 +00:00
|
|
|
fn test_bookmark_list_conflicted() {
|
2024-03-22 12:43:43 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-03-22 12:43:43 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
// Track existing bookmark. Local bookmark should result in conflict.
|
2024-03-22 12:43:43 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "a"]);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "b"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "bar"]);
|
2024-03-22 12:43:43 +00:00
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
2024-08-21 19:59:15 +00:00
|
|
|
&["bookmark", "create", "foo", "-r", "description(a)"],
|
2024-03-22 12:43:43 +00:00
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
&repo_path,
|
|
|
|
&[
|
2024-08-21 19:59:15 +00:00
|
|
|
"bookmark",
|
2024-03-22 12:43:43 +00:00
|
|
|
"create",
|
|
|
|
"foo",
|
|
|
|
"-r",
|
|
|
|
"description(b)",
|
|
|
|
"--at-op=@-",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["status"]);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
|
2024-03-22 12:43:43 +00:00
|
|
|
bar: kkmpptxz 06a973bc (empty) b
|
|
|
|
foo (conflicted):
|
|
|
|
+ rlvkpnrz d8d5f980 (empty) a
|
|
|
|
+ kkmpptxz 06a973bc (empty) b
|
|
|
|
"###);
|
2024-08-21 19:59:15 +00:00
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["bookmark", "list", "--conflicted"]), @r###"
|
2024-03-22 12:43:43 +00:00
|
|
|
foo (conflicted):
|
|
|
|
+ rlvkpnrz d8d5f980 (empty) a
|
|
|
|
+ kkmpptxz 06a973bc (empty) b
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-05-02 19:58:32 +00:00
|
|
|
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
2024-08-21 19:59:15 +00:00
|
|
|
let template = r#"bookmarks ++ " " ++ commit_id.short()"#;
|
2023-02-28 10:43:14 +00:00
|
|
|
test_env.jj_cmd_success(cwd, &["log", "-T", template])
|
2022-05-02 19:58:32 +00:00
|
|
|
}
|
2023-06-13 21:49:51 +00:00
|
|
|
|
2024-08-21 19:59:15 +00:00
|
|
|
fn get_bookmark_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
|
|
// --quiet to suppress deleted bookmarks hint
|
|
|
|
test_env.jj_cmd_success(repo_path, &["bookmark", "list", "--all-remotes", "--quiet"])
|
2023-06-13 21:49:51 +00:00
|
|
|
}
|