Skip to content

Commit ee2c795

Browse files
apenwarrgitster
authored andcommitted
Teach git-pull to pass -X<option> to git-merge
This needs the usual sq then eval trick to allow IFS characters in the option. Signed-off-by: Avery Pennarun <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cc5b29 commit ee2c795

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

git-pull.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ test -z "$(git ls-files -u)" ||
1818

1919
strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
2020
log_arg= verbosity=
21+
merge_args=
2122
curr_branch=$(git symbolic-ref -q HEAD)
2223
curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
2324
rebase=$(git config --bool branch.$curr_branch_short.rebase)
@@ -62,6 +63,18 @@ do
6263
esac
6364
strategy_args="${strategy_args}-s $strategy "
6465
;;
66+
-X*)
67+
case "$#,$1" in
68+
1,-X)
69+
usage ;;
70+
*,-X)
71+
xx="-X $2"
72+
shift ;;
73+
*,*)
74+
xx="$1" ;;
75+
esac
76+
merge_args="$merge_args$xx "
77+
;;
6578
-r|--r|--re|--reb|--reba|--rebas|--rebase)
6679
rebase=true
6780
;;
@@ -216,7 +229,7 @@ fi
216229

217230
merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
218231
test true = "$rebase" &&
219-
exec git-rebase $diffstat $strategy_args --onto $merge_head \
232+
exec git-rebase $diffstat $strategy_args $merge_args --onto $merge_head \
220233
${oldremoteref:-$merge_head}
221-
exec git-merge $diffstat $no_commit $squash $no_ff $ff_only $log_arg $strategy_args \
234+
exec git-merge $diffstat $no_commit $squash $no_ff $ff_only $log_arg $strategy_args $merge_args \
222235
"$merge_name" HEAD $merge_head $verbosity

t/t6037-merge-ours-theirs.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ test_expect_success 'recursive favouring ours' '
5353
! grep 1 file
5454
'
5555

56+
test_expect_success 'pull with -X' '
57+
git reset --hard master && git pull -s recursive -Xours . side &&
58+
git reset --hard master && git pull -s recursive -X ours . side &&
59+
git reset --hard master && git pull -s recursive -Xtheirs . side &&
60+
git reset --hard master && git pull -s recursive -X theirs . side &&
61+
git reset --hard master && ! git pull -s recursive -X bork . side
62+
'
63+
5664
test_done

0 commit comments

Comments
 (0)