From fc4b109e5b467df5304262f1a2ce3d2c7c7e489e Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 18 Jun 2022 20:05:08 -0700 Subject: [PATCH] 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. --- CHANGELOG.md | 3 +++ src/commands.rs | 24 +----------------------- tests/test_git_push.rs | 35 +---------------------------------- 3 files changed, 5 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c98a4021..a7c384b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` argument, which can be used diff --git a/src/commands.rs b/src/commands.rs index dc48d7d75..0ffd2e1c3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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)), } } diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 0ebfa1297..fc8c74e91 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -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), ""), @r###" - Creating 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();