Skip to content

Commit

Permalink
bookmark: add "b" alias
Browse files Browse the repository at this point in the history
`jj bookmark` is a frequently used command. Its subcommands already have
one letter aliases. Defining `jj b` as an alias for `jj bookmarks` make
bookmarks really easy to use.
  • Loading branch information
samueltardieu committed Sep 17, 2024
1 parent e25ec53 commit 05c6d62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# all aliases from here.
[aliases]
amend = ["squash"]
b = ["bookmark"]
co = ["checkout"]
unamend = ["unsquash"]

Expand Down
14 changes: 7 additions & 7 deletions cli/tests/test_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn test_alias_basic() {
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let repo_path = test_env.env_root().join("repo");

test_env.add_config(r#"aliases.b = ["log", "-r", "@", "-T", "bookmarks"]"#);
test_env.add_config(r#"aliases.bk = ["log", "-r", "@", "-T", "bookmarks"]"#);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["bk"]);
insta::assert_snapshot!(stdout, @r###"
@ my-bookmark
Expand All @@ -41,20 +41,20 @@ fn test_alias_legacy_section() {
let repo_path = test_env.env_root().join("repo");

// Can define aliases in [alias] section
test_env.add_config(r#"alias.b = ["log", "-r", "@", "-T", "bookmarks"]"#);
test_env.add_config(r#"alias.bk = ["log", "-r", "@", "-T", "bookmarks"]"#);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["bk"]);
insta::assert_snapshot!(stdout, @r###"
@ my-bookmark
~
"###);

// The same alias (name) in both [alias] and [aliases] sections is an error
test_env.add_config(r#"aliases.b = ["bookmark", "list"]"#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["b"]);
test_env.add_config(r#"aliases.bk = ["bookmark", "list"]"#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["bk"]);
insta::assert_snapshot!(stderr, @r###"
Error: Alias "b" is defined in both [aliases] and [alias]
Error: Alias "bk" is defined in both [aliases] and [alias]
Hint: [aliases] is the preferred section for aliases. Please remove the alias from [alias].
"###);
}
Expand Down
9 changes: 9 additions & 0 deletions docs/bookmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,13 @@ To resolve a conflicted state in a remote bookmark (e.g. `main@origin`), simply
pull from the remote (e.g. `jj git fetch`). The conflict resolution will also
propagate to the local bookmark (which was presumably also conflicted).

## Ease of use

The use of bookmarks is frequent in some workflows, for example, when
interacting with Git repositories containing branches. To this end,
one-letter shortcuts have been implemented, both for the `jj bookmark`
command itself through an alias (as `jj b`), and for its subcommands.
For example, `jj bookmark create BOOKMARK-NAME` can be abbreviated as
`jj b c BOOKMARK-NAME`.

[design]: design/tracking-branches.md

0 comments on commit 05c6d62

Please sign in to comment.