Skip to content

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

feat: Allow special symbols in merge target

Maximilian Roosa3d1590f03ec
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 672b0486e..0cb024d15 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -311,10 +311,11 @@ impl Repository {
/// Resolve a target branch from an optional override
///
- /// If target is Some, returns it as a String. Otherwise, queries the default branch.
+ /// If target is Some, expands special symbols ("@", "-", "^") via `resolve_worktree_name`.
+ /// Otherwise, queries the default branch.
/// This is a common pattern used throughout commands that accept an optional --target flag.
pub fn resolve_target_branch(&self, target: Option<&str>) -> anyhow::Result<String> {
- target.map_or_else(|| self.default_branch(), |b| Ok(b.to_string()))
+ target.map_or_else(|| self.default_branch(), |b| self.resolve_worktree_name(b))
}
/// Infer the default branch locally (without remote).
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 5ce9a51d2..626763108 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -364,6 +364,14 @@ fn test_merge_to_default_branch() {
snapshot_merge("merge_to_default", &repo, &[], Some(&feature_wt));
}
+#[test]
+fn test_merge_with_caret_symbol() {
+ let (repo, feature_wt) = setup_merge_scenario();
+
+ // Merge using ^ symbol (should resolve to default branch)
+ snapshot_merge("merge_with_caret", &repo, &["^"], Some(&feature_wt));
+}
+
#[test]
fn test_merge_error_detached_head() {
let repo = TestRepo::new();
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_with_caret.snap b/tests/snapshots/integration__integration_tests__merge__merge_with_caret.snap
new file mode 100644
index 000000000..3edb2d7dd
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_with_caret.snap
@@ -0,0 +1,31 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ - ^
+ env:
+ 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: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Merging 1 commit to main @ [SHA] (no commit/squash/rebase needed)
+  * [SHA] Add feature file
+  feature.txt | 1 +
+  1 file changed, 1 insertion(+)
+βœ… Merged to main (1 commit, 1 file, +1)
+πŸ”„ Removing feature worktree & branch in background
+
+----- stderr -----