apply --reverse: tie it all together.
Add a few tests, usage string, and documentation. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Aug 16, 2006 at 16:09 UTC
2cda1a214e9d2e362242027b4b622ecb3d9260de
3 files changed
+49
-6
Documentation/git-apply.txt
+5
-1
@@ -10,7 +10,8 @@ SYNOPSIS
10
--------
11
[verse]
12
'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply]
13
- [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM]
13
+ [--no-add] [--index-info] [--allow-binary-replacement]
14
+ [--reverse] [-z] [-pNUM]
15
[-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>]
16
[<patch>...]
17
@@ -62,6 +63,9 @@ OPTIONS
63
the original version of the blob is available locally,
64
outputs information about them to the standard output.
65
66
+--reverse::
67
+ Apply the patch in reverse.
68
+
69
-z::
70
When showing the index information, do not munge paths,
71
but use NUL terminated machine readable format. Without
builtin-apply.c
+1
-1
@@ -43,7 +43,7 @@ static int show_index_info;
43
static int line_termination = '\n';
44
static unsigned long p_context = -1;
45
static const char apply_usage[] =
46
-"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
46
+"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
47
48
static enum whitespace_eol {
49
nowarn_whitespace,
t/t4116-apply-reverse.sh
+43
-4
@@ -22,25 +22,64 @@ test_expect_success setup '
22
tr "[mon]" '\''[\0\1\2]'\'' <file1 >file2 &&
23
24
git commit -a -m second &&
25
+ git tag second &&
26
26
- git diff --binary -R initial >patch
27
+ git diff --binary initial second >patch
28
29
'
30
31
test_expect_success 'apply in forward' '
32
33
+ T0=`git rev-parse "second^{tree}"` &&
34
+ git reset --hard initial &&
35
git apply --index --binary patch &&
33
- git diff initial >diff &&
34
- diff -u /dev/null diff
35
-
36
+ T1=`git write-tree` &&
37
+ test "$T0" = "$T1"
38
'
39
40
test_expect_success 'apply in reverse' '
41
42
+ git reset --hard second &&
43
git apply --reverse --binary --index patch &&
44
git diff >diff &&
45
diff -u /dev/null diff
46
47
'
48
49
+test_expect_success 'setup separate repository lacking postimage' '
50
+
51
+ git tar-tree initial initial | tar xf - &&
52
+ (
53
+ cd initial && git init-db && git add .
54
+ ) &&
55
+
56
+ git tar-tree second second | tar xf - &&
57
+ (
58
+ cd second && git init-db && git add .
59
+ )
60
+
61
+'
62
+
63
+test_expect_success 'apply in forward without postimage' '
64
+
65
+ T0=`git rev-parse "second^{tree}"` &&
66
+ (
67
+ cd initial &&
68
+ git apply --index --binary ../patch &&
69
+ T1=`git write-tree` &&
70
+ test "$T0" = "$T1"
71
+ )
72
+'
73
+
74
+test_expect_success 'apply in reverse without postimage' '
75
+
76
+ T0=`git rev-parse "initial^{tree}"` &&
77
+ (
78
+ cd second &&
79
+ git apply --index --binary --reverse ../patch &&
80
+ T1=`git write-tree` &&
81
+ test "$T0" = "$T1"
82
+ )
83
+'
84
+
85
test_done