mirror of
https://https.git.savannah.gnu.org/git/patch.git
synced 2026-01-26 08:07:53 +00:00
155 lines
2.3 KiB
Plaintext
155 lines
2.3 KiB
Plaintext
# Copyright 2010-2025 Free Software Foundation, Inc.
|
|
#
|
|
# Copying and distribution of this file, with or without modification,
|
|
# in any medium, are permitted without royalty provided the copyright
|
|
# notice and this notice are preserved.
|
|
|
|
# git diffs: copy and rename tests
|
|
|
|
. $srcdir/test-lib.sh
|
|
|
|
require cat
|
|
use_local_patch
|
|
use_tmpdir
|
|
|
|
# ==============================================================
|
|
# Normal copy and rename patches
|
|
|
|
echo old > f
|
|
|
|
cat > copy.diff <<EOF
|
|
diff --git a/f b/g
|
|
copy from f
|
|
copy to g
|
|
index 3367afd..3e75765 100644
|
|
--- a/f
|
|
+++ b/g
|
|
@@ -1 +1 @@
|
|
-old
|
|
+new
|
|
EOF
|
|
|
|
check 'patch -p1 < copy.diff || echo "Status: $?"' <<EOF
|
|
patching file g (copied from f)
|
|
EOF
|
|
|
|
check 'cat f' <<EOF
|
|
old
|
|
EOF
|
|
|
|
check 'cat g' <<EOF
|
|
new
|
|
EOF
|
|
|
|
cat > rename.diff <<EOF
|
|
diff --git a/f b/h
|
|
rename from f
|
|
rename to h
|
|
index 3367afd..3e75765 100644
|
|
--- a/f
|
|
+++ b/h
|
|
@@ -1 +1 @@
|
|
-old
|
|
+new
|
|
EOF
|
|
|
|
check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
|
|
patching file h (renamed from f)
|
|
EOF
|
|
|
|
ncheck 'test ! -e f'
|
|
|
|
check 'cat h' <<EOF
|
|
new
|
|
EOF
|
|
|
|
echo old > h
|
|
|
|
check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
|
|
patching file h (already renamed from f)
|
|
EOF
|
|
|
|
ncheck 'test ! -e f'
|
|
|
|
check 'cat h' <<EOF
|
|
new
|
|
EOF
|
|
|
|
mv h f
|
|
|
|
check 'patch -p1 -R < rename.diff || echo "Status: $?"' <<EOF
|
|
patching file f (already renamed from h)
|
|
EOF
|
|
|
|
ncheck 'test ! -e h'
|
|
|
|
check 'cat f' <<EOF
|
|
old
|
|
EOF
|
|
|
|
# --------------------------------------------------------------
|
|
# Patches with no hunks
|
|
|
|
echo old > f
|
|
rm -f g h
|
|
|
|
cat > copy.diff <<EOF
|
|
diff --git a/f a/g
|
|
copy from f
|
|
copy to g
|
|
EOF
|
|
|
|
check 'patch -p1 < copy.diff || echo "Status: $?"' <<EOF
|
|
patching file g (copied from f)
|
|
EOF
|
|
|
|
check 'cat f' <<EOF
|
|
old
|
|
EOF
|
|
|
|
check 'cat g' <<EOF
|
|
old
|
|
EOF
|
|
|
|
cat > rename.diff <<EOF
|
|
diff --git a/f a/h
|
|
rename from f
|
|
rename to h
|
|
EOF
|
|
|
|
check 'patch -p1 < rename.diff || echo "Status: $?"' <<EOF
|
|
patching file h (renamed from f)
|
|
EOF
|
|
|
|
ncheck 'test ! -e f'
|
|
|
|
check 'cat h' <<EOF
|
|
old
|
|
EOF
|
|
|
|
# --------------------------------------------------------------
|
|
# Backup file tests
|
|
|
|
echo old > f
|
|
rm -f g h
|
|
|
|
check 'patch -p1 --backup < copy.diff || echo "Status: $?"' <<EOF
|
|
patching file g (copied from f)
|
|
EOF
|
|
|
|
ncheck 'test ! -e f.orig'
|
|
|
|
ncheck 'cat g.orig'
|
|
|
|
rm -f f.orig g.orig
|
|
|
|
check 'patch -p1 --backup < rename.diff || echo "Status: $?"' <<EOF
|
|
patching file h (renamed from f)
|
|
EOF
|
|
|
|
check 'cat f.orig' <<EOF
|
|
old
|
|
EOF
|
|
|
|
ncheck 'cat h.orig'
|