Commit c76cde67 by Mislav Marohnić

Make `--patch` compatible with git diff patches

Filenames in git diff patches are prefixed by default by "a/" (source)
and "b/" destination. Such patches don't work with ruby-builds `--patch`
option since it internally uses `patch -p0`.

Prior workarounds were to use either an intermediate step:

    filterdiff --strip=1

or to generate the patch without the prefix in the first place:

    git diff --no-prefix ...

Now, git diff patches are detected by searching for this pattern:

    diff --git a/...

And `patch -p1` is used by default in such cases to strip the 1st
component of filename paths.

Fixes #521, closes #484
parent 74b21936
......@@ -846,9 +846,15 @@ isolated_gem_install() {
}
apply_ruby_patch() {
local patchfile
case "$1" in
ruby-* | jruby-* | rubinius-* )
patch -p0 --force -i "${2:--}"
patchfile="$(mktemp -t ruby-patch)"
cat "${2:--}" >"$patchfile"
local striplevel=0
grep -q '^diff --git a/' "$patchfile" && striplevel=1
patch -p$striplevel --force -i "$patchfile"
;;
esac
}
......
......@@ -85,9 +85,9 @@ OUT
stub brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" >> build.log'
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
install_fixture --patch definitions/needs-yaml
echo | TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml
assert_success
unstub make
......@@ -97,7 +97,33 @@ OUT
yaml-0.1.6: --prefix=$INSTALL_ROOT
make -j 2
make install
patch -p0 --force -i -
patch -p0 --force -i $TMP/ruby-patch.XXX
ruby-2.0.0: --prefix=$INSTALL_ROOT
make -j 2
make install
OUT
}
@test "apply ruby patch from git diff before building" {
cached_tarball "yaml-0.1.6"
cached_tarball "ruby-2.0.0"
stub brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
echo 'diff --git a/script.rb' | TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml
assert_success
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.6: --prefix=$INSTALL_ROOT
make -j 2
make install
patch -p1 --force -i $TMP/ruby-patch.XXX
ruby-2.0.0: --prefix=$INSTALL_ROOT
make -j 2
make install
......
Markdown is supported
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