Skip to content

Commit

Permalink
cli: print out short change ids with jj git push --change
Browse files Browse the repository at this point in the history
The follow up diff will make `-c` accept large revsets, so it won't make any
sense to print out the original expression when multiple branches will be
created from it.

Signed-off-by: Austin Seipp <[email protected]>
  • Loading branch information
thoughtpolice committed Jun 19, 2024
1 parent 31b8f07 commit 6e8d82d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ fn update_change_branches(
for change_arg in changes {
let workspace_command = tx.base_workspace_helper();
let commit = workspace_command.resolve_single_rev(change_arg)?;
let short_change_id = short_change_hash(commit.change_id());
let mut branch_name = format!("{branch_prefix}{}", commit.change_id().hex());
let view = tx.base_repo().view();
if view.get_local_branch(&branch_name).is_absent() {
// A local branch with the full change ID doesn't exist already, so use the
// short ID if it's not ambiguous (which it shouldn't be most of the time).
let short_change_id = short_change_hash(commit.change_id());
if workspace_command
.resolve_single_rev(&RevisionArg::from(short_change_id.clone()))
.is_ok()
Expand All @@ -484,7 +484,7 @@ fn update_change_branches(
if view.get_local_branch(&branch_name).is_absent() {
writeln!(
ui.status(),
"Creating branch {branch_name} for revision {change_arg}",
"Creating branch {branch_name} for revision {short_change_id}",
)?;
}
tx.mut_repo()
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ fn test_git_push_changes() {
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--change", "@"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Creating branch push-yostqsxwqrlt for revision @
Creating branch push-yostqsxwqrlt for revision yostqsxwqrlt
Branch changes to push to origin:
Add branch push-yostqsxwqrlt to 28d7620ea63a
"###);
Expand All @@ -589,7 +589,7 @@ fn test_git_push_changes() {
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=@", "-c=@-"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Creating branch push-yqosqzytrlsw for revision @-
Creating branch push-yqosqzytrlsw for revision yqosqzytrlsw
Branch changes to push to origin:
Move sideways branch push-yostqsxwqrlt from 28d7620ea63a to 48d8c7948133
Add branch push-yqosqzytrlsw to fa16a14170fb
Expand Down Expand Up @@ -664,7 +664,7 @@ fn test_git_push_changes() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Creating branch test-yostqsxwqrlt for revision @
Creating branch test-yostqsxwqrlt for revision yostqsxwqrlt
Branch changes to push to origin:
Add branch test-yostqsxwqrlt to 3e2ce808759b
"###);
Expand Down Expand Up @@ -759,7 +759,7 @@ fn test_git_push_mixed() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Creating branch push-yqosqzytrlsw for revision @--
Creating branch push-yqosqzytrlsw for revision yqosqzytrlsw
Branch changes to push to origin:
Add branch push-yqosqzytrlsw to fa16a14170fb
Add branch branch-1 to 7decc7932d9c
Expand Down

0 comments on commit 6e8d82d

Please sign in to comment.