Skip to content

Commit b91a13b

Browse files
committed
Merge branch 'jc/am-3-nonstandard-popt' into maint
The code to synthesize the fake ancestor tree used by 3-way merge fallback in "git am" was not prepared to read a patch created with a non-standard -p<num> value. * jc/am-3-nonstandard-popt: test: "am -3" can accept non-standard -p<num> am -3: allow nonstandard -p<num> option
2 parents 0dbe659 + a61ba26 commit b91a13b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

git-am.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,18 @@ fall_back_3way () {
127127
mkdir "$dotest/patch-merge-tmp-dir"
128128

129129
# First see if the patch records the index info that we can use.
130-
git apply --build-fake-ancestor "$dotest/patch-merge-tmp-index" \
131-
"$dotest/patch" &&
130+
cmd="git apply $git_apply_opt --build-fake-ancestor" &&
131+
cmd="$cmd "'"$dotest/patch-merge-tmp-index" "$dotest/patch"' &&
132+
eval "$cmd" &&
132133
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
133134
git write-tree >"$dotest/patch-merge-base+" ||
134135
cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")"
135136

136137
say Using index info to reconstruct a base tree...
137-
if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
138-
git apply --cached <"$dotest/patch"
138+
139+
cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"'
140+
cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"'
141+
if eval "$cmd"
139142
then
140143
mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
141144
mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"

t/t4150-am.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ test_expect_success setup '
123123
git commit -m "added another file" &&
124124
125125
git format-patch --stdout master >lorem-move.patch &&
126+
git format-patch --no-prefix --stdout master >lorem-zero.patch &&
126127
127128
git checkout -b rename &&
128129
git mv file renamed &&
@@ -276,6 +277,20 @@ test_expect_success 'am -3 falls back to 3-way merge' '
276277
git diff --exit-code lorem
277278
'
278279

280+
test_expect_success 'am -3 -p0 can read --no-prefix patch' '
281+
rm -fr .git/rebase-apply &&
282+
git reset --hard &&
283+
git checkout -b lorem3 master2 &&
284+
sed -n -e "3,\$p" msg >file &&
285+
head -n 9 msg >>file &&
286+
git add file &&
287+
test_tick &&
288+
git commit -m "copied stuff" &&
289+
git am -3 -p0 lorem-zero.patch &&
290+
! test -d .git/rebase-apply &&
291+
git diff --exit-code lorem
292+
'
293+
279294
test_expect_success 'am can rename a file' '
280295
grep "^rename from" rename.patch &&
281296
rm -fr .git/rebase-apply &&

0 commit comments

Comments
 (0)