git push: do not consider @- if @ has non-empty content or description

This commit is contained in:
Samuel Tardieu 2023-03-05 21:27:03 +01:00
parent 616058c2fa
commit decca920c7
3 changed files with 43 additions and 6 deletions

View file

@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`++` operator, `concat()`, or `separate()` function instead.
Example: `description ++ "\n"`
* `jj git push` will consider pushing the parent commit only when the
current commit has no content and no description, such as right after
a `jj squash`.
### New features
* `jj git push --deleted` will remove all locally deleted branches from the remote.

View file

@ -703,13 +703,15 @@ fn cmd_git_push(
&RefTarget::Normal(wc_commit.clone()),
);
if branches.is_empty() {
// Try @- instead if it has exactly one parent, such as after `jj squash`
// Try @- instead if @ is discardable
let commit = workspace_command.repo().store().get_commit(wc_commit)?;
if let [parent] = commit.parent_ids() {
branches = find_branches_targeting(
workspace_command.repo().view(),
&RefTarget::Normal(parent.clone()),
);
if commit.is_discardable() {
if let [parent_commit_id] = commit.parent_ids() {
branches = find_branches_targeting(
workspace_command.repo().view(),
&RefTarget::Normal(parent_commit_id.clone()),
);
}
}
}
if branches.is_empty() {

View file

@ -119,6 +119,37 @@ fn test_git_push_parent_branch() {
"###);
}
#[test]
fn test_git_no_push_parent_branch_non_empty_commit() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_success(
&workspace_root,
&["describe", "-m", "modified branch1 commit"],
);
test_env.jj_cmd_success(&workspace_root, &["new"]);
std::fs::write(workspace_root.join("file"), "file").unwrap();
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--dry-run"]);
insta::assert_snapshot!(stderr, @r###"
Error: No current branch.
"###);
}
#[test]
fn test_git_no_push_parent_branch_description() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_success(
&workspace_root,
&["describe", "-m", "modified branch1 commit"],
);
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "non-empty description"]);
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--dry-run"]);
insta::assert_snapshot!(stderr, @r###"
Error: No current branch.
"###);
}
#[test]
fn test_git_push_no_current_branch() {
let (test_env, workspace_root) = set_up();