Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Remove --allow-merge-commits flag, allow merge commits by default (#297)

Maximilian Roos2052bdd84c8c
diff --git a/src/cli.rs b/src/cli.rs
index 73864c8f3..f5d8c3966 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -920,10 +920,6 @@ pub enum StepCommand {
/// Defaults to default branch.
#[arg(add = crate::completion::branch_value_completer())]
target: Option<String>,
-
- /// Allow merge commits
- #[arg(long)]
- allow_merge_commits: bool,
},
/// Rebase onto target
diff --git a/src/commands/merge.rs b/src/commands/merge.rs
index 92dec79b0..a28647e26 100644
--- a/src/commands/merge.rs
+++ b/src/commands/merge.rs
@@ -210,7 +210,6 @@ pub fn handle_merge(opts: MergeOptions<'_>) -> anyhow::Result<()> {
// Fast-forward push to target branch with commit/squash/rebase info for consolidated message
handle_push(
Some(&target_branch),
- false,
"Merged to",
Some(MergeOperations {
committed,
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index 3cfe4d43d..bbcdb5c8c 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -949,7 +949,6 @@ impl<'a> CommandContext<'a> {
/// overlaps with the push range.
pub fn handle_push(
target: Option<&str>,
- allow_merge_commits: bool,
verb: &str,
operations: Option<MergeOperations>,
) -> anyhow::Result<()> {
@@ -985,15 +984,6 @@ pub fn handle_push(
.into());
}
- // Check for merge commits unless allowed
- let has_merge_commits = repo.has_merge_commits(&target_branch, "HEAD")?;
- if !allow_merge_commits && has_merge_commits {
- return Err(GitError::MergeCommitsFound {
- target_branch: target_branch.clone(),
- }
- .into());
- }
-
// Check for conflicting changes in target worktree (auto-stash safe changes)
let mut target_worktree_stash =
repo.prepare_target_worktree(target_worktree_path.as_ref(), &target_branch)?;
@@ -1042,11 +1032,6 @@ pub fn handle_push(
}
}
- // Flag acknowledgments
- if allow_merge_commits && has_merge_commits {
- notes.push("merge commits allowed".to_string());
- }
-
let operations_note = if notes.is_empty() {
String::new()
} else {
diff --git a/src/git/error.rs b/src/git/error.rs
index e31d1d9e4..8ef2a5eaa 100644
--- a/src/git/error.rs
+++ b/src/git/error.rs
@@ -101,9 +101,6 @@ pub enum GitError {
commits_formatted: String,
in_merge_context: bool,
},
- MergeCommitsFound {
- target_branch: String,
- },
RebaseConflict {
target_branch: String,
git_output: String,
@@ -384,20 +381,6 @@ impl std::fmt::Display for GitError {
}
}
- GitError::MergeCommitsFound { target_branch } => {
- let merge_cmd = suggest_command("merge", &[], &["--allow-merge-commits"]);
- write!(
- f,
- "{}\n\n{}",
- error_message(cformat!(
- "Can't push to local <bold>{target_branch}</> branch: found merge commits"
- )),
- hint_message(cformat!(
- "To push non-linear history, run <bright-black>{merge_cmd}</>"
- ))
- )
- }
-
GitError::RebaseConflict {
target_branch,
git_output,
@@ -1025,18 +1008,6 @@ mod tests {
assert!(display.contains("wt step rebase"));
}
- #[test]
- fn test_git_error_merge_commits_found() {
- let err = GitError::MergeCommitsFound {
- target_branch: "main".into(),
- };
- let display = err.to_string();
- assert!(display.contains("push to local"));
- assert!(display.contains("main"));
- assert!(display.contains("merge commits"));
- assert!(display.contains("--allow-merge-commits"));
- }
-
#[test]
fn test_git_error_rebase_conflict() {
// With git output
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 913cf7879..15ae470fc 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -711,13 +711,6 @@ impl Repository {
.context("Failed to parse commit count")
}
- /// Check if there are merge commits in the range base..head.
- pub fn has_merge_commits(&self, base: &str, head: &str) -> anyhow::Result<bool> {
- let range = format!("{}..{}", base, head);
- let stdout = self.run_command(&["rev-list", "--merges", &range])?;
- Ok(!stdout.trim().is_empty())
- }
-
/// Get files changed between base and head.
///
/// For renames and copies, both old and new paths are included to ensure
diff --git a/src/main.rs b/src/main.rs
index ab6205d32..716790ce1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1107,10 +1107,7 @@ fn main() {
}
Ok(())
}),
- StepCommand::Push {
- target,
- allow_merge_commits,
- } => handle_push(target.as_deref(), allow_merge_commits, "Pushed to", None),
+ StepCommand::Push { target } => handle_push(target.as_deref(), "Pushed to", None),
StepCommand::Rebase { target } => {
handle_rebase(target.as_deref()).and_then(|result| match result {
RebaseResult::Rebased => Ok(()),
diff --git a/tests/integration_tests/git_error_display.rs b/tests/integration_tests/git_error_display.rs
index a1712e6e4..937b8b2d8 100644
--- a/tests/integration_tests/git_error_display.rs
+++ b/tests/integration_tests/git_error_display.rs
@@ -180,15 +180,6 @@ fn display_not_fast_forward_merge_context() {
assert_snapshot!("not_fast_forward_merge_context", err.to_string());
}
-#[test]
-fn display_merge_commits_found() {
- let err = GitError::MergeCommitsFound {
- target_branch: "main".into(),
- };
-
- assert_snapshot!("merge_commits_found", err.to_string());
-}
-
#[test]
fn display_rebase_conflict() {
let err = GitError::RebaseConflict {
diff --git a/tests/integration_tests/push.rs b/tests/integration_tests/push.rs
index f5fa100cb..2e7d3801b 100644
--- a/tests/integration_tests/push.rs
+++ b/tests/integration_tests/push.rs
@@ -229,7 +229,7 @@ fn test_push_error_not_fast_forward(mut repo: TestRepo) {
}
#[rstest]
-fn test_push_error_with_merge_commits(mut repo: TestRepo) {
+fn test_push_with_merge_commits(mut repo: TestRepo) {
// Create feature branch with initial commit
let feature_wt = repo.add_worktree_with_commit("feature", "file1.txt", "content1", "Commit 1");
@@ -258,54 +258,15 @@ fn test_push_error_with_merge_commits(mut repo: TestRepo) {
.output()
.unwrap();
- // Try to push to main (should fail - has merge commits)
+ // Push to main (should succeed - merge commits are allowed)
snapshot_push(
- "push_error_with_merge_commits",
+ "push_with_merge_commits",
&repo,
&["main"],
Some(&feature_wt),
);
}
-#[rstest]
-fn test_push_with_merge_commits_allowed(mut repo: TestRepo) {
- // Create feature branch with initial commit
- let feature_wt = repo.add_worktree_with_commit("feature", "file1.txt", "content1", "Commit 1");
-
- // Create another branch for merging
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "-b", "temp"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- repo.commit_in_worktree(&feature_wt, "file2.txt", "content2", "Commit 2");
-
- // Switch back to feature and merge temp (creating merge commit)
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["checkout", "feature"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["merge", "temp", "--no-ff", "-m", "Merge temp"])
- .current_dir(&feature_wt)
- .output()
- .unwrap();
-
- // Push to main with --allow-merge-commits (should succeed with acknowledgment)
- snapshot_push(
- "push_with_merge_commits_allowed",
- &repo,
- &["main", "--allow-merge-commits"],
- Some(&feature_wt),
- );
-}
-
#[rstest]
fn test_push_no_remote(#[from(repo_with_feature_worktree)] repo: TestRepo) {
// Note: repo_with_feature_worktree doesn't call setup_remote(), so this tests the "no remote" error case
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap b/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap
deleted file mode 100644
index 0300a14b9..000000000
--- a/tests/integration_tests/snapshots/integration__integration_tests__git_error_display__merge_commits_found.snap
+++ /dev/null
@@ -1,7 +0,0 @@
----
-source: tests/integration_tests/git_error_display.rs
-expression: err.to_string()
----
-✗ Can't push to local main branch: found merge commits
-
-↳ To push non-linear history, run wt merge --allow-merge-commits
diff --git a/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap b/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap
deleted file mode 100644
index c8c38c616..000000000
--- a/tests/snapshots/integration__integration_tests__push__push_error_with_merge_commits.snap
+++ /dev/null
@@ -1,36 +0,0 @@
----
-source: tests/integration_tests/push.rs
-info:
- program: wt
- args:
- - step
- - push
- - main
- env:
- APPDATA: "[TEST_CONFIG_HOME]"
- CLICOLOR_FORCE: "1"
- COLUMNS: "150"
- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
- GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
- GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
- GIT_TERMINAL_PROMPT: "0"
- HOME: "[TEST_HOME]"
- LANG: C
- LC_ALL: C
- PATH: "[PATH]"
- RUST_LOG: warn
- SOURCE_DATE_EPOCH: "1735776000"
- USERPROFILE: "[TEST_HOME]"
- WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
- XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
----
-success: false
-exit_code: 1
------ stdout -----
-
------ stderr -----
-✗ Can't push to local main branch: found merge commits
-
-↳ To push non-linear history, run wt merge --allow-merge-commits
diff --git a/tests/snapshots/integration__integration_tests__push__push_with_merge_commits_allowed.snap b/tests/snapshots/integration__integration_tests__push__push_with_merge_commits.snap
similarity index 94%
rename from tests/snapshots/integration__integration_tests__push__push_with_merge_commits_allowed.snap
rename to tests/snapshots/integration__integration_tests__push__push_with_merge_commits.snap
index 025aa0e52..c848398dd 100644
--- a/tests/snapshots/integration__integration_tests__push__push_with_merge_commits_allowed.snap
+++ b/tests/snapshots/integration__integration_tests__push__push_with_merge_commits.snap
@@ -6,7 +6,6 @@ info:
- step
- push
- main
- - "--allow-merge-commits"
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
@@ -32,7 +31,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-◎ Pushing 3 commits to main @ 2489484 (merge commits allowed)
+◎ Pushing 3 commits to main @ 2489484
  * 2489484 Merge temp
  |/
  | * e03c938 Commit 2