Commit 132510ea authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Daniel Vetter
Browse files

dim: Check that patches have git-format-patch default prefixes

By default the git-format-patch command generates patches with prefixes
for the source and destination (-p1), and is also what git-am uses as a
default. The command strips the first leading path component when patch
is applied (unless a different -p<num> argument is used).

But the patch generating behaviour can be changed with git-format-patch
--no-prefix argument (or setting 'diff.noprefix = true' in .gitconfig).

Patches with no source and destination prefixes can confuse the git-am
3-way merge logic, since stripping the first path component will lead
to wrong paths for newly added files.

To avoid this, check that patches to apply are using git-format-patch's
defaults prefixes to make sure that git-am defaults are safe to use too.

Since there are developers that generate patches without using git, make
this an error but allow to still continue when using the dim -f option.
Signed-off-by: Javier Martinez Canillas's avatarJavier Martinez Canillas <>
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <>
parent 0666fb79
Pipeline #494005 passed with stages
in 47 seconds
......@@ -1113,6 +1113,18 @@ function check_merge_baseline
# ensure the patch has prefixes (-p1), since otherwise it can confuse the git am
# 3-way merge logic. check the default source (a/) and destination (b/) prefixes.
function check_diff_prefix
local rv
rv=$(grep -q -E "^diff --git a\/.+ b\/.+$" $patch)
return $rv
# ensure we're on branch $1, and apply patches. the rest of the arguments are
# passed to git am.
......@@ -1139,6 +1151,11 @@ function dim_apply_branch
git mailsplit -b -o$dir $file > /dev/null
for patch in "$dir"/*; do
if ! check_diff_prefix "$patch"; then
warn_or_fail "Patch does not contain prefixes in its diff and can confuse git-am when applying"
if ! apply_patch $patch "$@"; then
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment