commit - d224ad331179af78d8a4f232001f0a6595e36d85
commit + be53ddb1cf400566466802853561b948acaa613e
blob - 47f1113850fb0008036c2a317d9d93163797019f
blob + 26f7367c64b4782476828a3a83a22a307a19c83d
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
struct imsgbuf ibuf;
static const struct got_error *
-send_patch(const char *oldname, const char *newname)
+send_patch(const char *oldname, const char *newname, int git)
{
struct got_imsg_patch p;
memset(&p, 0, sizeof(p));
- if (oldname != NULL)
+ /*
+ * Prefer the new name if it's not /dev/null and it's not
+ * a git-style diff.
+ */
+ if (!git && newname != NULL && oldname != NULL)
+ strlcpy(p.old, newname, sizeof(p.old));
+ else if (oldname != NULL)
strlcpy(p.old, oldname, sizeof(p.old));
+
if (newname != NULL)
strlcpy(p.new, newname, sizeof(p.new));
(!create && old == NULL))
err = got_error(GOT_ERR_PATCH_MALFORMED);
else
- err = send_patch(old, new);
+ err = send_patch(old, new, git);
if (err)
break;
blob - 32c852932a5cc8f51426acc413933a80b95f41de
blob + 7be41fc2a24825f9f6432515b0f6f0c1f93b403b
--- regress/cmdline/patch.sh
+++ regress/cmdline/patch.sh
fi
cat <<EOF > $testroot/wt/patch
---- alpha
-+++ eta
+diff --git a/alpha b/eta
+--- a/alpha
++++ b/eta
@@ -0,0 +0,0 @@
EOF
rm $testroot/wt/eta
cat <<EOF > $testroot/wt/patch
---- alpha
-+++ eta
+diff --git a/alpha b/eta
+--- a/alpha
++++ b/eta
@@ -1 +1,2 @@
alpha
+but now is eta
+++ /dev/null
@@ -1 +0,0 @@
-beta
+diff --git a/gamma/delta b/gamma/delta.new
--- gamma/delta
+++ gamma/delta.new
@@ -1 +1 @@
M numbers
@@ -47,7 +47,7 @@ applied with offset -10
@@ -87,7 +87,7 @@ applied with offset 10
+EOF
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done $testroot $ret
+}
+
+test_patch_prefer_new_path() {
+ local testroot=`test_init patch_orig`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ test_done $testroot $ret
+ return 1
+ fi
+
+ cat <<EOF > $testroot/wt/patch
+--- alpha.orig
++++ alpha
+@@ -1 +1,2 @@
+ alpha
++was edited
EOF
+ (cd $testroot/wt && got patch patch) > $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ test_done $testroot $ret
+ return 1
+ fi
+
+ echo 'M alpha' > $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret=$?
if [ $ret -ne 0 ]; then
run_test test_patch_preserve_perm
run_test test_patch_create_dirs
run_test test_patch_with_offset
+run_test test_patch_prefer_new_path