From aab82cd641f823792dd357aaac2c31f5f9b0c390 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Wed, 19 Jun 2024 13:09:00 -0500 Subject: [PATCH] cli: print out short change ids with `jj git push --change` 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 --- cli/src/commands/git/push.rs | 4 ++-- cli/tests/test_git_push.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index 40596b65a..f93c1225d 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -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() @@ -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() diff --git a/cli/tests/test_git_push.rs b/cli/tests/test_git_push.rs index 9e3b01ce2..c5b709d5f 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -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 "###); @@ -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 @@ -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 "###); @@ -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