THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
6.9KB

  1. #!/bin/sh
  2. test_description='range-diff tests'
  3. . ./test-lib.sh
  4. # Note that because of the range-diff's heuristics, test_commit does more
  5. # harm than good. We need some real history.
  6. test_expect_success 'setup' '
  7. git fast-import < "$TEST_DIRECTORY"/t3206/history.export
  8. '
  9. test_expect_success 'simple A..B A..C (unmodified)' '
  10. git range-diff --no-color master..topic master..unmodified \
  11. >actual &&
  12. cat >expected <<-EOF &&
  13. 1: 4de457d = 1: 35b9b25 s/5/A/
  14. 2: fccce22 = 2: de345ab s/4/A/
  15. 3: 147e64e = 3: 9af6654 s/11/B/
  16. 4: a63e992 = 4: 2901f77 s/12/B/
  17. EOF
  18. test_cmp expected actual
  19. '
  20. test_expect_success 'simple B...C (unmodified)' '
  21. git range-diff --no-color topic...unmodified >actual &&
  22. # same "expected" as above
  23. test_cmp expected actual
  24. '
  25. test_expect_success 'simple A B C (unmodified)' '
  26. git range-diff --no-color master topic unmodified >actual &&
  27. # same "expected" as above
  28. test_cmp expected actual
  29. '
  30. test_expect_success 'trivial reordering' '
  31. git range-diff --no-color master topic reordered >actual &&
  32. cat >expected <<-EOF &&
  33. 1: 4de457d = 1: aca177a s/5/A/
  34. 3: 147e64e = 2: 14ad629 s/11/B/
  35. 4: a63e992 = 3: ee58208 s/12/B/
  36. 2: fccce22 = 4: 307b27a s/4/A/
  37. EOF
  38. test_cmp expected actual
  39. '
  40. test_expect_success 'removed a commit' '
  41. git range-diff --no-color master topic removed >actual &&
  42. cat >expected <<-EOF &&
  43. 1: 4de457d = 1: 7657159 s/5/A/
  44. 2: fccce22 < -: ------- s/4/A/
  45. 3: 147e64e = 2: 43d84d3 s/11/B/
  46. 4: a63e992 = 3: a740396 s/12/B/
  47. EOF
  48. test_cmp expected actual
  49. '
  50. test_expect_success 'added a commit' '
  51. git range-diff --no-color master topic added >actual &&
  52. cat >expected <<-EOF &&
  53. 1: 4de457d = 1: 2716022 s/5/A/
  54. 2: fccce22 = 2: b62accd s/4/A/
  55. -: ------- > 3: df46cfa s/6/A/
  56. 3: 147e64e = 4: 3e64548 s/11/B/
  57. 4: a63e992 = 5: 12b4063 s/12/B/
  58. EOF
  59. test_cmp expected actual
  60. '
  61. test_expect_success 'new base, A B C' '
  62. git range-diff --no-color master topic rebased >actual &&
  63. cat >expected <<-EOF &&
  64. 1: 4de457d = 1: cc9c443 s/5/A/
  65. 2: fccce22 = 2: c5d9641 s/4/A/
  66. 3: 147e64e = 3: 28cc2b6 s/11/B/
  67. 4: a63e992 = 4: 5628ab7 s/12/B/
  68. EOF
  69. test_cmp expected actual
  70. '
  71. test_expect_success 'new base, B...C' '
  72. # this syntax includes the commits from master!
  73. git range-diff --no-color topic...rebased >actual &&
  74. cat >expected <<-EOF &&
  75. -: ------- > 1: a31b12e unrelated
  76. 1: 4de457d = 2: cc9c443 s/5/A/
  77. 2: fccce22 = 3: c5d9641 s/4/A/
  78. 3: 147e64e = 4: 28cc2b6 s/11/B/
  79. 4: a63e992 = 5: 5628ab7 s/12/B/
  80. EOF
  81. test_cmp expected actual
  82. '
  83. test_expect_success 'changed commit' '
  84. git range-diff --no-color topic...changed >actual &&
  85. cat >expected <<-EOF &&
  86. 1: 4de457d = 1: a4b3333 s/5/A/
  87. 2: fccce22 = 2: f51d370 s/4/A/
  88. 3: 147e64e ! 3: 0559556 s/11/B/
  89. @@
  90. 9
  91. 10
  92. -11
  93. -+B
  94. ++BB
  95. 12
  96. 13
  97. 14
  98. 4: a63e992 ! 4: d966c5c s/12/B/
  99. @@
  100. @@ A
  101. 9
  102. 10
  103. - B
  104. + BB
  105. -12
  106. +B
  107. 13
  108. EOF
  109. test_cmp expected actual
  110. '
  111. test_expect_success 'changed commit with --no-patch diff option' '
  112. git range-diff --no-color --no-patch topic...changed >actual &&
  113. cat >expected <<-EOF &&
  114. 1: 4de457d = 1: a4b3333 s/5/A/
  115. 2: fccce22 = 2: f51d370 s/4/A/
  116. 3: 147e64e ! 3: 0559556 s/11/B/
  117. 4: a63e992 ! 4: d966c5c s/12/B/
  118. EOF
  119. test_cmp expected actual
  120. '
  121. test_expect_success 'changed commit with --stat diff option' '
  122. git range-diff --no-color --stat topic...changed >actual &&
  123. cat >expected <<-EOF &&
  124. 1: 4de457d = 1: a4b3333 s/5/A/
  125. a => b | 0
  126. 1 file changed, 0 insertions(+), 0 deletions(-)
  127. 2: fccce22 = 2: f51d370 s/4/A/
  128. a => b | 0
  129. 1 file changed, 0 insertions(+), 0 deletions(-)
  130. 3: 147e64e ! 3: 0559556 s/11/B/
  131. a => b | 0
  132. 1 file changed, 0 insertions(+), 0 deletions(-)
  133. 4: a63e992 ! 4: d966c5c s/12/B/
  134. a => b | 0
  135. 1 file changed, 0 insertions(+), 0 deletions(-)
  136. EOF
  137. test_cmp expected actual
  138. '
  139. test_expect_success 'changed commit with sm config' '
  140. git range-diff --no-color --submodule=log topic...changed >actual &&
  141. cat >expected <<-EOF &&
  142. 1: 4de457d = 1: a4b3333 s/5/A/
  143. 2: fccce22 = 2: f51d370 s/4/A/
  144. 3: 147e64e ! 3: 0559556 s/11/B/
  145. @@
  146. 9
  147. 10
  148. -11
  149. -+B
  150. ++BB
  151. 12
  152. 13
  153. 14
  154. 4: a63e992 ! 4: d966c5c s/12/B/
  155. @@
  156. @@ A
  157. 9
  158. 10
  159. - B
  160. + BB
  161. -12
  162. +B
  163. 13
  164. EOF
  165. test_cmp expected actual
  166. '
  167. test_expect_success 'no commits on one side' '
  168. git commit --amend -m "new message" &&
  169. git range-diff master HEAD@{1} HEAD
  170. '
  171. test_expect_success 'changed message' '
  172. git range-diff --no-color topic...changed-message >actual &&
  173. sed s/Z/\ /g >expected <<-EOF &&
  174. 1: 4de457d = 1: f686024 s/5/A/
  175. 2: fccce22 ! 2: 4ab067d s/4/A/
  176. @@
  177. Z
  178. Z s/4/A/
  179. Z
  180. + Also a silly comment here!
  181. +
  182. Z diff --git a/file b/file
  183. Z --- a/file
  184. Z +++ b/file
  185. 3: 147e64e = 3: b9cb956 s/11/B/
  186. 4: a63e992 = 4: 8add5f1 s/12/B/
  187. EOF
  188. test_cmp expected actual
  189. '
  190. test_expect_success 'dual-coloring' '
  191. sed -e "s|^:||" >expect <<-\EOF &&
  192. :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
  193. :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
  194. : <REVERSE><CYAN>@@<RESET>
  195. : <RESET>
  196. : s/4/A/<RESET>
  197. : <RESET>
  198. : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
  199. : <REVERSE><GREEN>+<RESET>
  200. : diff --git a/file b/file<RESET>
  201. : --- a/file<RESET>
  202. : +++ b/file<RESET>
  203. :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
  204. : <REVERSE><CYAN>@@<RESET>
  205. : 9<RESET>
  206. : 10<RESET>
  207. : <RED> -11<RESET>
  208. : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
  209. : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
  210. : 12<RESET>
  211. : 13<RESET>
  212. : 14<RESET>
  213. :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
  214. : <REVERSE><CYAN>@@<RESET>
  215. : <CYAN> @@ A<RESET>
  216. : 9<RESET>
  217. : 10<RESET>
  218. : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
  219. : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
  220. : <RED> -12<RESET>
  221. : <GREEN> +B<RESET>
  222. : 13<RESET>
  223. EOF
  224. git range-diff changed...changed-message --color --dual-color >actual.raw &&
  225. test_decode_color >actual <actual.raw &&
  226. test_cmp expect actual
  227. '
  228. for prev in topic master..topic
  229. do
  230. test_expect_success "format-patch --range-diff=$prev" '
  231. git format-patch --cover-letter --range-diff=$prev \
  232. master..unmodified >actual &&
  233. test_when_finished "rm 000?-*" &&
  234. test_line_count = 5 actual &&
  235. test_i18ngrep "^Range-diff:$" 0000-* &&
  236. grep "= 1: .* s/5/A" 0000-* &&
  237. grep "= 2: .* s/4/A" 0000-* &&
  238. grep "= 3: .* s/11/B" 0000-* &&
  239. grep "= 4: .* s/12/B" 0000-*
  240. '
  241. done
  242. test_expect_success 'format-patch --range-diff as commentary' '
  243. git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
  244. test_when_finished "rm 0001-*" &&
  245. test_line_count = 1 actual &&
  246. test_i18ngrep "^Range-diff:$" 0001-* &&
  247. grep "> 1: .* new message" 0001-*
  248. '
  249. test_done