forked from mirrors/jj
cli: don't say "Creating branch push-*" if it already exists
I was a bit surprised to see the message when I used `jj git push --change @-` on a commit that already had a branch because I had pushed it earlier. The fix means that we instead print the message even if we later abandon the transaction (so the branch-creation is not persisted) because the commit is open, for example. That's already what happens if the commit is missing a description, and since we're planning to remove the open/closed concept, I don't think this patch makes it much worse. We probably should improve it later by printing the message only once the push has succeeded.
This commit is contained in:
parent
39fc56dafb
commit
a4a148104c
2 changed files with 18 additions and 9 deletions
|
@ -4928,16 +4928,18 @@ fn cmd_git_push(
|
||||||
ui.settings().push_branch_prefix(),
|
ui.settings().push_branch_prefix(),
|
||||||
commit.change_id().hex()
|
commit.change_id().hex()
|
||||||
);
|
);
|
||||||
tx.mut_repo()
|
if tx.mut_repo().get_local_branch(&branch_name).is_none() {
|
||||||
.set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone()));
|
|
||||||
if let Some(update) =
|
|
||||||
branch_updates_for_push(tx.mut_repo().as_repo_ref(), &args.remote, &branch_name)?
|
|
||||||
{
|
|
||||||
writeln!(
|
writeln!(
|
||||||
ui,
|
ui,
|
||||||
"Creating branch {} for revision {}",
|
"Creating branch {} for revision {}",
|
||||||
branch_name, change_str
|
branch_name, change_str
|
||||||
)?;
|
)?;
|
||||||
|
}
|
||||||
|
tx.mut_repo()
|
||||||
|
.set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone()));
|
||||||
|
if let Some(update) =
|
||||||
|
branch_updates_for_push(tx.mut_repo().as_repo_ref(), &args.remote, &branch_name)?
|
||||||
|
{
|
||||||
branch_updates.insert(branch_name.clone(), update);
|
branch_updates.insert(branch_name.clone(), update);
|
||||||
} else {
|
} else {
|
||||||
writeln!(
|
writeln!(
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::common::TestEnvironment;
|
use regex::Regex;
|
||||||
|
|
||||||
|
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
||||||
|
@ -60,9 +62,14 @@ fn test_git_push_open() {
|
||||||
Error: Won't push open commit
|
Error: Won't push open commit
|
||||||
"###);
|
"###);
|
||||||
// When pushing with `--change`, won't push if it points to an open commit
|
// When pushing with `--change`, won't push if it points to an open commit
|
||||||
let stderr =
|
let assert = test_env
|
||||||
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--change", "my-branch"]);
|
.jj_cmd(&workspace_root, &["git", "push", "--change", "my-branch"])
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
.assert();
|
||||||
|
let branch_pattern = Regex::new("push-[0-9a-f]+").unwrap();
|
||||||
|
insta::assert_snapshot!(branch_pattern.replace(&get_stdout_string(&assert), "<branch>"), @r###"
|
||||||
|
Creating branch <branch> for revision my-branch
|
||||||
|
"###);
|
||||||
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
||||||
Error: Won't push open commit
|
Error: Won't push open commit
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue