t / t4109-apply-multifrag.shon commit git-svn: rename 'commit' command to 'set-tree' (3289e86)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4# Copyright (c) 2005 Robert Fitzsimons
   5#
   6
   7test_description='git-apply test patches with multiple fragments.
   8
   9'
  10. ./test-lib.sh
  11
  12# setup
  13
  14cat > patch1.patch <<\EOF
  15diff --git a/main.c b/main.c
  16new file mode 100644
  17--- /dev/null
  18+++ b/main.c
  19@@ -0,0 +1,23 @@
  20+#include <stdio.h>
  21+
  22+int func(int num);
  23+void print_int(int num);
  24+
  25+int main() {
  26+       int i;
  27+
  28+       for (i = 0; i < 10; i++) {
  29+               print_int(func(i));
  30+       }
  31+
  32+       return 0;
  33+}
  34+
  35+int func(int num) {
  36+       return num * num;
  37+}
  38+
  39+void print_int(int num) {
  40+       printf("%d", num);
  41+}
  42+
  43EOF
  44cat > patch2.patch <<\EOF
  45diff --git a/main.c b/main.c
  46--- a/main.c
  47+++ b/main.c
  48@@ -1,7 +1,9 @@
  49+#include <stdlib.h>
  50 #include <stdio.h>
  51 
  52 int func(int num);
  53 void print_int(int num);
  54+void print_ln();
  55 
  56 int main() {
  57        int i;
  58@@ -10,6 +12,8 @@
  59                print_int(func(i));
  60        }
  61 
  62+       print_ln();
  63+
  64        return 0;
  65 }
  66 
  67@@ -21,3 +25,7 @@
  68        printf("%d", num);
  69 }
  70 
  71+void print_ln() {
  72+       printf("\n");
  73+}
  74+
  75EOF
  76cat > patch3.patch <<\EOF
  77diff --git a/main.c b/main.c
  78--- a/main.c
  79+++ b/main.c
  80@@ -1,9 +1,7 @@
  81-#include <stdlib.h>
  82 #include <stdio.h>
  83 
  84 int func(int num);
  85 void print_int(int num);
  86-void print_ln();
  87 
  88 int main() {
  89        int i;
  90@@ -12,8 +10,6 @@
  91                print_int(func(i));
  92        }
  93 
  94-       print_ln();
  95-
  96        return 0;
  97 }
  98 
  99@@ -25,7 +21,3 @@
 100        printf("%d", num);
 101 }
 102 
 103-void print_ln() {
 104-       printf("\n");
 105-}
 106-
 107EOF
 108cat > patch4.patch <<\EOF
 109diff --git a/main.c b/main.c
 110--- a/main.c
 111+++ b/main.c
 112@@ -1,13 +1,14 @@
 113 #include <stdio.h>
 114 
 115 int func(int num);
 116-void print_int(int num);
 117+int func2(int num);
 118 
 119 int main() {
 120        int i;
 121 
 122        for (i = 0; i < 10; i++) {
 123-               print_int(func(i));
 124+               printf("%d", func(i));
 125+               printf("%d", func3(i));
 126        }
 127 
 128        return 0;
 129@@ -17,7 +18,7 @@
 130        return num * num;
 131 }
 132 
 133-void print_int(int num) {
 134-       printf("%d", num);
 135+int func2(int num) {
 136+       return num * num * num;
 137 }
 138 
 139EOF
 140
 141test_expect_success "S = git-apply (1)" \
 142    'git-apply patch1.patch patch2.patch'
 143mv main.c main.c.git
 144
 145test_expect_success "S = patch (1)" \
 146    'cat patch1.patch patch2.patch | patch -p1'
 147
 148test_expect_success "S = cmp (1)" \
 149    'cmp main.c.git main.c'
 150
 151rm -f main.c main.c.git
 152
 153test_expect_success "S = git-apply (2)" \
 154    'git-apply patch1.patch patch2.patch patch3.patch'
 155mv main.c main.c.git
 156
 157test_expect_success "S = patch (2)" \
 158    'cat patch1.patch patch2.patch patch3.patch | patch -p1'
 159
 160test_expect_success "S = cmp (2)" \
 161    'cmp main.c.git main.c'
 162
 163rm -f main.c main.c.git
 164
 165test_expect_success "S = git-apply (3)" \
 166    'git-apply patch1.patch patch4.patch'
 167mv main.c main.c.git
 168
 169test_expect_success "S = patch (3)" \
 170    'cat patch1.patch patch4.patch | patch -p1'
 171
 172test_expect_success "S = cmp (3)" \
 173    'cmp main.c.git main.c'
 174
 175test_done
 176