ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: allow pushing open commits

Since we're thinking of removing the concept of open and closed
commits, we can't use that open/closed distinction to decide to not
push some commits.
This commit is contained in:
Martin von Zweigbergk 2022-06-18 20:05:08 -07:00 committed by Martin von Zweigbergk
parent 8667e374b8
commit fc4b109e5b
3 changed files with 5 additions and 57 deletions

View file

@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The [`$NO_COLOR` environment variable](https://no-color.org/) no longer
overrides the `ui.color` configuration if explicitly set.
* `jj git push` no longer aborts if you attempt to push an open commit (but it
now aborts if a commit does not have a description).
### New features
* `jj rebase` now accepts a `--branch/-b <revision>` argument, which can be used

View file

@ -5012,18 +5012,6 @@ fn cmd_git_push(
BranchPushAction::LocalConflicted => {}
BranchPushAction::RemoteConflicted => {}
BranchPushAction::Update(update) => {
if let Some(new_target) = &update.new_target {
let new_target_commit = repo.store().get_commit(new_target)?;
// TODO: Should we also skip branches that have open commits as ancestors?
if new_target_commit.is_open() {
writeln!(
ui,
"Skipping branch '{}' since it points to an open commit.",
branch_name
)?;
continue;
}
}
branch_updates.insert(branch_name.clone(), update);
}
}
@ -5123,17 +5111,7 @@ fn branch_updates_for_push(
"Branch {}@{} is conflicted",
branch_name, remote_name
))),
BranchPushAction::Update(update) => {
if let Some(new_target) = &update.new_target {
let new_target_commit = repo.store().get_commit(new_target)?;
if new_target_commit.is_open() {
return Err(CommandError::UserError(
"Won't push open commit".to_string(),
));
}
}
Ok(Some(update))
}
BranchPushAction::Update(update) => Ok(Some(update)),
}
}

View file

@ -14,9 +14,7 @@
use std::path::PathBuf;
use regex::Regex;
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};
use crate::common::TestEnvironment;
pub mod common;
@ -43,37 +41,6 @@ fn test_git_push_nothing() {
"###);
}
#[test]
fn test_git_push_open() {
let (test_env, workspace_root) = set_up();
// When pushing everything, won't push an open commit even if there's a branch
// on it
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Skipping branch 'my-branch' since it points to an open commit.
Nothing changed.
"###);
// When pushing a specific branch, won't push it if it points to an open commit
let stderr =
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch", "my-branch"]);
insta::assert_snapshot!(stderr, @r###"
Error: Won't push open commit
"###);
// When pushing with `--change`, won't push if it points to an open commit
let assert = test_env
.jj_cmd(&workspace_root, &["git", "push", "--change", "my-branch"])
.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
"###);
}
#[test]
fn test_git_push_conflict() {
let (test_env, workspace_root) = set_up();