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.

892 lines
27KB

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2007 Andy Parkins
  4. #
  5. test_description='for-each-ref test'
  6. . ./test-lib.sh
  7. . "$TEST_DIRECTORY"/lib-gpg.sh
  8. . "$TEST_DIRECTORY"/lib-terminal.sh
  9. # Mon Jul 3 23:18:43 2006 +0000
  10. datestamp=1151968723
  11. setdate_and_increment () {
  12. GIT_COMMITTER_DATE="$datestamp +0200"
  13. datestamp=$(expr "$datestamp" + 1)
  14. GIT_AUTHOR_DATE="$datestamp +0200"
  15. datestamp=$(expr "$datestamp" + 1)
  16. export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
  17. }
  18. test_expect_success setup '
  19. setdate_and_increment &&
  20. echo "Using $datestamp" > one &&
  21. git add one &&
  22. git commit -m "Initial" &&
  23. setdate_and_increment &&
  24. git tag -a -m "Tagging at $datestamp" testtag &&
  25. git update-ref refs/remotes/origin/master master &&
  26. git remote add origin nowhere &&
  27. git config branch.master.remote origin &&
  28. git config branch.master.merge refs/heads/master &&
  29. git remote add myfork elsewhere &&
  30. git config remote.pushdefault myfork &&
  31. git config push.default current
  32. '
  33. test_atom() {
  34. case "$1" in
  35. head) ref=refs/heads/master ;;
  36. tag) ref=refs/tags/testtag ;;
  37. sym) ref=refs/heads/sym ;;
  38. *) ref=$1 ;;
  39. esac
  40. printf '%s\n' "$3" >expected
  41. test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
  42. git for-each-ref --format='%($2)' $ref >actual &&
  43. sanitize_pgp <actual >actual.clean &&
  44. test_cmp expected actual.clean
  45. "
  46. }
  47. test_atom head refname refs/heads/master
  48. test_atom head refname: refs/heads/master
  49. test_atom head refname:short master
  50. test_atom head refname:lstrip=1 heads/master
  51. test_atom head refname:lstrip=2 master
  52. test_atom head refname:lstrip=-1 master
  53. test_atom head refname:lstrip=-2 heads/master
  54. test_atom head refname:rstrip=1 refs/heads
  55. test_atom head refname:rstrip=2 refs
  56. test_atom head refname:rstrip=-1 refs
  57. test_atom head refname:rstrip=-2 refs/heads
  58. test_atom head refname:strip=1 heads/master
  59. test_atom head refname:strip=2 master
  60. test_atom head refname:strip=-1 master
  61. test_atom head refname:strip=-2 heads/master
  62. test_atom head upstream refs/remotes/origin/master
  63. test_atom head upstream:short origin/master
  64. test_atom head upstream:lstrip=2 origin/master
  65. test_atom head upstream:lstrip=-2 origin/master
  66. test_atom head upstream:rstrip=2 refs/remotes
  67. test_atom head upstream:rstrip=-2 refs/remotes
  68. test_atom head upstream:strip=2 origin/master
  69. test_atom head upstream:strip=-2 origin/master
  70. test_atom head push refs/remotes/myfork/master
  71. test_atom head push:short myfork/master
  72. test_atom head push:lstrip=1 remotes/myfork/master
  73. test_atom head push:lstrip=-1 master
  74. test_atom head push:rstrip=1 refs/remotes/myfork
  75. test_atom head push:rstrip=-1 refs
  76. test_atom head push:strip=1 remotes/myfork/master
  77. test_atom head push:strip=-1 master
  78. test_atom head objecttype commit
  79. test_atom head objectsize 171
  80. test_atom head objectsize:disk 138
  81. test_atom head deltabase 0000000000000000000000000000000000000000
  82. test_atom head objectname $(git rev-parse refs/heads/master)
  83. test_atom head objectname:short $(git rev-parse --short refs/heads/master)
  84. test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
  85. test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
  86. test_atom head tree $(git rev-parse refs/heads/master^{tree})
  87. test_atom head parent ''
  88. test_atom head numparent 0
  89. test_atom head object ''
  90. test_atom head type ''
  91. test_atom head '*objectname' ''
  92. test_atom head '*objecttype' ''
  93. test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
  94. test_atom head authorname 'A U Thor'
  95. test_atom head authoremail '<author@example.com>'
  96. test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
  97. test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
  98. test_atom head committername 'C O Mitter'
  99. test_atom head committeremail '<committer@example.com>'
  100. test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
  101. test_atom head tag ''
  102. test_atom head tagger ''
  103. test_atom head taggername ''
  104. test_atom head taggeremail ''
  105. test_atom head taggerdate ''
  106. test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
  107. test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
  108. test_atom head subject 'Initial'
  109. test_atom head contents:subject 'Initial'
  110. test_atom head body ''
  111. test_atom head contents:body ''
  112. test_atom head contents:signature ''
  113. test_atom head contents 'Initial
  114. '
  115. test_atom head HEAD '*'
  116. test_atom tag refname refs/tags/testtag
  117. test_atom tag refname:short testtag
  118. test_atom tag upstream ''
  119. test_atom tag push ''
  120. test_atom tag objecttype tag
  121. test_atom tag objectsize 154
  122. test_atom tag objectsize:disk 138
  123. test_atom tag '*objectsize:disk' 138
  124. test_atom tag deltabase 0000000000000000000000000000000000000000
  125. test_atom tag '*deltabase' 0000000000000000000000000000000000000000
  126. test_atom tag objectname $(git rev-parse refs/tags/testtag)
  127. test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
  128. test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
  129. test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
  130. test_atom tag tree ''
  131. test_atom tag parent ''
  132. test_atom tag numparent ''
  133. test_atom tag object $(git rev-parse refs/tags/testtag^0)
  134. test_atom tag type 'commit'
  135. test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463'
  136. test_atom tag '*objecttype' 'commit'
  137. test_atom tag author ''
  138. test_atom tag authorname ''
  139. test_atom tag authoremail ''
  140. test_atom tag authordate ''
  141. test_atom tag committer ''
  142. test_atom tag committername ''
  143. test_atom tag committeremail ''
  144. test_atom tag committerdate ''
  145. test_atom tag tag 'testtag'
  146. test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
  147. test_atom tag taggername 'C O Mitter'
  148. test_atom tag taggeremail '<committer@example.com>'
  149. test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
  150. test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
  151. test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
  152. test_atom tag subject 'Tagging at 1151968727'
  153. test_atom tag contents:subject 'Tagging at 1151968727'
  154. test_atom tag body ''
  155. test_atom tag contents:body ''
  156. test_atom tag contents:signature ''
  157. test_atom tag contents 'Tagging at 1151968727
  158. '
  159. test_atom tag HEAD ' '
  160. test_expect_success 'Check invalid atoms names are errors' '
  161. test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
  162. '
  163. test_expect_success 'Check format specifiers are ignored in naming date atoms' '
  164. git for-each-ref --format="%(authordate)" refs/heads &&
  165. git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
  166. git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
  167. git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
  168. '
  169. test_expect_success 'Check valid format specifiers for date fields' '
  170. git for-each-ref --format="%(authordate:default)" refs/heads &&
  171. git for-each-ref --format="%(authordate:relative)" refs/heads &&
  172. git for-each-ref --format="%(authordate:short)" refs/heads &&
  173. git for-each-ref --format="%(authordate:local)" refs/heads &&
  174. git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
  175. git for-each-ref --format="%(authordate:rfc2822)" refs/heads
  176. '
  177. test_expect_success 'Check invalid format specifiers are errors' '
  178. test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
  179. '
  180. test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
  181. test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
  182. test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
  183. test_must_fail git for-each-ref --format="%(objectname:short=foo)"
  184. '
  185. test_date () {
  186. f=$1 &&
  187. committer_date=$2 &&
  188. author_date=$3 &&
  189. tagger_date=$4 &&
  190. cat >expected <<-EOF &&
  191. 'refs/heads/master' '$committer_date' '$author_date'
  192. 'refs/tags/testtag' '$tagger_date'
  193. EOF
  194. (
  195. git for-each-ref --shell \
  196. --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
  197. refs/heads &&
  198. git for-each-ref --shell \
  199. --format="%(refname) %(taggerdate${f:+:$f})" \
  200. refs/tags
  201. ) >actual &&
  202. test_cmp expected actual
  203. }
  204. test_expect_success 'Check unformatted date fields output' '
  205. test_date "" \
  206. "Tue Jul 4 01:18:43 2006 +0200" \
  207. "Tue Jul 4 01:18:44 2006 +0200" \
  208. "Tue Jul 4 01:18:45 2006 +0200"
  209. '
  210. test_expect_success 'Check format "default" formatted date fields output' '
  211. test_date default \
  212. "Tue Jul 4 01:18:43 2006 +0200" \
  213. "Tue Jul 4 01:18:44 2006 +0200" \
  214. "Tue Jul 4 01:18:45 2006 +0200"
  215. '
  216. test_expect_success 'Check format "default-local" date fields output' '
  217. test_date default-local "Mon Jul 3 23:18:43 2006" "Mon Jul 3 23:18:44 2006" "Mon Jul 3 23:18:45 2006"
  218. '
  219. # Don't know how to do relative check because I can't know when this script
  220. # is going to be run and can't fake the current time to git, and hence can't
  221. # provide expected output. Instead, I'll just make sure that "relative"
  222. # doesn't exit in error
  223. test_expect_success 'Check format "relative" date fields output' '
  224. f=relative &&
  225. (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
  226. git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
  227. '
  228. # We just check that this is the same as "relative" for now.
  229. test_expect_success 'Check format "relative-local" date fields output' '
  230. test_date relative-local \
  231. "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
  232. "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
  233. "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
  234. '
  235. test_expect_success 'Check format "short" date fields output' '
  236. test_date short 2006-07-04 2006-07-04 2006-07-04
  237. '
  238. test_expect_success 'Check format "short-local" date fields output' '
  239. test_date short-local 2006-07-03 2006-07-03 2006-07-03
  240. '
  241. test_expect_success 'Check format "local" date fields output' '
  242. test_date local \
  243. "Mon Jul 3 23:18:43 2006" \
  244. "Mon Jul 3 23:18:44 2006" \
  245. "Mon Jul 3 23:18:45 2006"
  246. '
  247. test_expect_success 'Check format "iso8601" date fields output' '
  248. test_date iso8601 \
  249. "2006-07-04 01:18:43 +0200" \
  250. "2006-07-04 01:18:44 +0200" \
  251. "2006-07-04 01:18:45 +0200"
  252. '
  253. test_expect_success 'Check format "iso8601-local" date fields output' '
  254. test_date iso8601-local "2006-07-03 23:18:43 +0000" "2006-07-03 23:18:44 +0000" "2006-07-03 23:18:45 +0000"
  255. '
  256. test_expect_success 'Check format "rfc2822" date fields output' '
  257. test_date rfc2822 \
  258. "Tue, 4 Jul 2006 01:18:43 +0200" \
  259. "Tue, 4 Jul 2006 01:18:44 +0200" \
  260. "Tue, 4 Jul 2006 01:18:45 +0200"
  261. '
  262. test_expect_success 'Check format "rfc2822-local" date fields output' '
  263. test_date rfc2822-local "Mon, 3 Jul 2006 23:18:43 +0000" "Mon, 3 Jul 2006 23:18:44 +0000" "Mon, 3 Jul 2006 23:18:45 +0000"
  264. '
  265. test_expect_success 'Check format "raw" date fields output' '
  266. test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
  267. '
  268. test_expect_success 'Check format "raw-local" date fields output' '
  269. test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
  270. '
  271. test_expect_success 'Check format of strftime date fields' '
  272. echo "my date is 2006-07-04" >expected &&
  273. git for-each-ref \
  274. --format="%(authordate:format:my date is %Y-%m-%d)" \
  275. refs/heads >actual &&
  276. test_cmp expected actual
  277. '
  278. test_expect_success 'Check format of strftime-local date fields' '
  279. echo "my date is 2006-07-03" >expected &&
  280. git for-each-ref \
  281. --format="%(authordate:format-local:my date is %Y-%m-%d)" \
  282. refs/heads >actual &&
  283. test_cmp expected actual
  284. '
  285. test_expect_success 'exercise strftime with odd fields' '
  286. echo >expected &&
  287. git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
  288. test_cmp expected actual &&
  289. long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
  290. echo $long >expected &&
  291. git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
  292. test_cmp expected actual
  293. '
  294. cat >expected <<\EOF
  295. refs/heads/master
  296. refs/remotes/origin/master
  297. refs/tags/testtag
  298. EOF
  299. test_expect_success 'Verify ascending sort' '
  300. git for-each-ref --format="%(refname)" --sort=refname >actual &&
  301. test_cmp expected actual
  302. '
  303. cat >expected <<\EOF
  304. refs/tags/testtag
  305. refs/remotes/origin/master
  306. refs/heads/master
  307. EOF
  308. test_expect_success 'Verify descending sort' '
  309. git for-each-ref --format="%(refname)" --sort=-refname >actual &&
  310. test_cmp expected actual
  311. '
  312. cat >expected <<\EOF
  313. refs/tags/testtag
  314. refs/tags/testtag-2
  315. EOF
  316. test_expect_success 'exercise patterns with prefixes' '
  317. git tag testtag-2 &&
  318. test_when_finished "git tag -d testtag-2" &&
  319. git for-each-ref --format="%(refname)" \
  320. refs/tags/testtag refs/tags/testtag-2 >actual &&
  321. test_cmp expected actual
  322. '
  323. cat >expected <<\EOF
  324. refs/tags/testtag
  325. refs/tags/testtag-2
  326. EOF
  327. test_expect_success 'exercise glob patterns with prefixes' '
  328. git tag testtag-2 &&
  329. test_when_finished "git tag -d testtag-2" &&
  330. git for-each-ref --format="%(refname)" \
  331. refs/tags/testtag "refs/tags/testtag-*" >actual &&
  332. test_cmp expected actual
  333. '
  334. cat >expected <<\EOF
  335. 'refs/heads/master'
  336. 'refs/remotes/origin/master'
  337. 'refs/tags/testtag'
  338. EOF
  339. test_expect_success 'Quoting style: shell' '
  340. git for-each-ref --shell --format="%(refname)" >actual &&
  341. test_cmp expected actual
  342. '
  343. test_expect_success 'Quoting style: perl' '
  344. git for-each-ref --perl --format="%(refname)" >actual &&
  345. test_cmp expected actual
  346. '
  347. test_expect_success 'Quoting style: python' '
  348. git for-each-ref --python --format="%(refname)" >actual &&
  349. test_cmp expected actual
  350. '
  351. cat >expected <<\EOF
  352. "refs/heads/master"
  353. "refs/remotes/origin/master"
  354. "refs/tags/testtag"
  355. EOF
  356. test_expect_success 'Quoting style: tcl' '
  357. git for-each-ref --tcl --format="%(refname)" >actual &&
  358. test_cmp expected actual
  359. '
  360. for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
  361. test_expect_success "more than one quoting style: $i" "
  362. test_must_fail git for-each-ref $i 2>err &&
  363. grep '^error: more than one quoting style' err
  364. "
  365. done
  366. test_expect_success 'setup for upstream:track[short]' '
  367. test_commit two
  368. '
  369. test_atom head upstream:track '[ahead 1]'
  370. test_atom head upstream:trackshort '>'
  371. test_atom head upstream:track,nobracket 'ahead 1'
  372. test_atom head upstream:nobracket,track 'ahead 1'
  373. test_expect_success 'setup for push:track[short]' '
  374. test_commit third &&
  375. git update-ref refs/remotes/myfork/master master &&
  376. git reset master~1
  377. '
  378. test_atom head push:track '[behind 1]'
  379. test_atom head push:trackshort '<'
  380. test_expect_success 'Check that :track[short] cannot be used with other atoms' '
  381. test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
  382. test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
  383. '
  384. test_expect_success 'Check that :track[short] works when upstream is invalid' '
  385. cat >expected <<-\EOF &&
  386. [gone]
  387. EOF
  388. test_when_finished "git config branch.master.merge refs/heads/master" &&
  389. git config branch.master.merge refs/heads/does-not-exist &&
  390. git for-each-ref \
  391. --format="%(upstream:track)$LF%(upstream:trackshort)" \
  392. refs/heads >actual &&
  393. test_cmp expected actual
  394. '
  395. test_expect_success 'Check for invalid refname format' '
  396. test_must_fail git for-each-ref --format="%(refname:INVALID)"
  397. '
  398. test_expect_success 'set up color tests' '
  399. cat >expected.color <<-EOF &&
  400. $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
  401. $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
  402. $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
  403. $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
  404. $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
  405. $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
  406. EOF
  407. sed "s/<[^>]*>//g" <expected.color >expected.bare &&
  408. color_format="%(objectname:short) %(color:green)%(refname:short)"
  409. '
  410. test_expect_success TTY '%(color) shows color with a tty' '
  411. test_terminal git for-each-ref --format="$color_format" >actual.raw &&
  412. test_decode_color <actual.raw >actual &&
  413. test_cmp expected.color actual
  414. '
  415. test_expect_success '%(color) does not show color without tty' '
  416. TERM=vt100 git for-each-ref --format="$color_format" >actual &&
  417. test_cmp expected.bare actual
  418. '
  419. test_expect_success '--color can override tty check' '
  420. git for-each-ref --color --format="$color_format" >actual.raw &&
  421. test_decode_color <actual.raw >actual &&
  422. test_cmp expected.color actual
  423. '
  424. test_expect_success 'color.ui=always does not override tty check' '
  425. git -c color.ui=always for-each-ref --format="$color_format" >actual &&
  426. test_cmp expected.bare actual
  427. '
  428. cat >expected <<\EOF
  429. heads/master
  430. tags/master
  431. EOF
  432. test_expect_success 'Check ambiguous head and tag refs (strict)' '
  433. git config --bool core.warnambiguousrefs true &&
  434. git checkout -b newtag &&
  435. echo "Using $datestamp" > one &&
  436. git add one &&
  437. git commit -m "Branch" &&
  438. setdate_and_increment &&
  439. git tag -m "Tagging at $datestamp" master &&
  440. git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
  441. test_cmp expected actual
  442. '
  443. cat >expected <<\EOF
  444. heads/master
  445. master
  446. EOF
  447. test_expect_success 'Check ambiguous head and tag refs (loose)' '
  448. git config --bool core.warnambiguousrefs false &&
  449. git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
  450. test_cmp expected actual
  451. '
  452. cat >expected <<\EOF
  453. heads/ambiguous
  454. ambiguous
  455. EOF
  456. test_expect_success 'Check ambiguous head and tag refs II (loose)' '
  457. git checkout master &&
  458. git tag ambiguous testtag^0 &&
  459. git branch ambiguous testtag^0 &&
  460. git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
  461. test_cmp expected actual
  462. '
  463. test_expect_success 'create tag without tagger' '
  464. git tag -a -m "Broken tag" taggerless &&
  465. git tag -f taggerless $(git cat-file tag taggerless |
  466. sed -e "/^tagger /d" |
  467. git hash-object --stdin -w -t tag)
  468. '
  469. test_atom refs/tags/taggerless type 'commit'
  470. test_atom refs/tags/taggerless tag 'taggerless'
  471. test_atom refs/tags/taggerless tagger ''
  472. test_atom refs/tags/taggerless taggername ''
  473. test_atom refs/tags/taggerless taggeremail ''
  474. test_atom refs/tags/taggerless taggerdate ''
  475. test_atom refs/tags/taggerless committer ''
  476. test_atom refs/tags/taggerless committername ''
  477. test_atom refs/tags/taggerless committeremail ''
  478. test_atom refs/tags/taggerless committerdate ''
  479. test_atom refs/tags/taggerless subject 'Broken tag'
  480. test_expect_success 'an unusual tag with an incomplete line' '
  481. git tag -m "bogo" bogo &&
  482. bogo=$(git cat-file tag bogo) &&
  483. bogo=$(printf "%s" "$bogo" | git mktag) &&
  484. git tag -f bogo "$bogo" &&
  485. git for-each-ref --format "%(body)" refs/tags/bogo
  486. '
  487. test_expect_success 'create tag with subject and body content' '
  488. cat >>msg <<-\EOF &&
  489. the subject line
  490. first body line
  491. second body line
  492. EOF
  493. git tag -F msg subject-body
  494. '
  495. test_atom refs/tags/subject-body subject 'the subject line'
  496. test_atom refs/tags/subject-body body 'first body line
  497. second body line
  498. '
  499. test_atom refs/tags/subject-body contents 'the subject line
  500. first body line
  501. second body line
  502. '
  503. test_expect_success 'create tag with multiline subject' '
  504. cat >msg <<-\EOF &&
  505. first subject line
  506. second subject line
  507. first body line
  508. second body line
  509. EOF
  510. git tag -F msg multiline
  511. '
  512. test_atom refs/tags/multiline subject 'first subject line second subject line'
  513. test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
  514. test_atom refs/tags/multiline body 'first body line
  515. second body line
  516. '
  517. test_atom refs/tags/multiline contents:body 'first body line
  518. second body line
  519. '
  520. test_atom refs/tags/multiline contents:signature ''
  521. test_atom refs/tags/multiline contents 'first subject line
  522. second subject line
  523. first body line
  524. second body line
  525. '
  526. test_expect_success GPG 'create signed tags' '
  527. git tag -s -m "" signed-empty &&
  528. git tag -s -m "subject line" signed-short &&
  529. cat >msg <<-\EOF &&
  530. subject line
  531. body contents
  532. EOF
  533. git tag -s -F msg signed-long
  534. '
  535. sig='-----BEGIN PGP SIGNATURE-----
  536. -----END PGP SIGNATURE-----
  537. '
  538. PREREQ=GPG
  539. test_atom refs/tags/signed-empty subject ''
  540. test_atom refs/tags/signed-empty contents:subject ''
  541. test_atom refs/tags/signed-empty body "$sig"
  542. test_atom refs/tags/signed-empty contents:body ''
  543. test_atom refs/tags/signed-empty contents:signature "$sig"
  544. test_atom refs/tags/signed-empty contents "$sig"
  545. test_atom refs/tags/signed-short subject 'subject line'
  546. test_atom refs/tags/signed-short contents:subject 'subject line'
  547. test_atom refs/tags/signed-short body "$sig"
  548. test_atom refs/tags/signed-short contents:body ''
  549. test_atom refs/tags/signed-short contents:signature "$sig"
  550. test_atom refs/tags/signed-short contents "subject line
  551. $sig"
  552. test_atom refs/tags/signed-long subject 'subject line'
  553. test_atom refs/tags/signed-long contents:subject 'subject line'
  554. test_atom refs/tags/signed-long body "body contents
  555. $sig"
  556. test_atom refs/tags/signed-long contents:body 'body contents
  557. '
  558. test_atom refs/tags/signed-long contents:signature "$sig"
  559. test_atom refs/tags/signed-long contents "subject line
  560. body contents
  561. $sig"
  562. cat >expected <<EOF
  563. $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
  564. $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
  565. EOF
  566. test_expect_success 'Verify sort with multiple keys' '
  567. git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
  568. refs/tags/bogo refs/tags/master > actual &&
  569. test_cmp expected actual
  570. '
  571. test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
  572. test_when_finished "git checkout master" &&
  573. git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
  574. sed -e "s/^\* / /" actual >expect &&
  575. git checkout --orphan orphaned-branch &&
  576. git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
  577. test_cmp expect actual
  578. '
  579. cat >trailers <<EOF
  580. Reviewed-by: A U Thor <author@example.com>
  581. Signed-off-by: A U Thor <author@example.com>
  582. [ v2 updated patch description ]
  583. Acked-by: A U Thor
  584. <author@example.com>
  585. EOF
  586. unfold () {
  587. perl -0pe 's/\n\s+/ /g'
  588. }
  589. test_expect_success 'set up trailers for next test' '
  590. echo "Some contents" > two &&
  591. git add two &&
  592. git commit -F - <<-EOF
  593. trailers: this commit message has trailers
  594. Some message contents
  595. $(cat trailers)
  596. EOF
  597. '
  598. test_expect_success '%(trailers:unfold) unfolds trailers' '
  599. git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
  600. {
  601. unfold <trailers
  602. echo
  603. } >expect &&
  604. test_cmp expect actual
  605. '
  606. test_expect_success '%(trailers:only) shows only "key: value" trailers' '
  607. git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
  608. {
  609. grep -v patch.description <trailers &&
  610. echo
  611. } >expect &&
  612. test_cmp expect actual
  613. '
  614. test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
  615. git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
  616. git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
  617. test_cmp actual reverse &&
  618. {
  619. grep -v patch.description <trailers | unfold &&
  620. echo
  621. } >expect &&
  622. test_cmp expect actual
  623. '
  624. test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
  625. git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
  626. {
  627. unfold <trailers
  628. echo
  629. } >expect &&
  630. test_cmp expect actual
  631. '
  632. test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
  633. git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
  634. {
  635. grep -v patch.description <trailers &&
  636. echo
  637. } >expect &&
  638. test_cmp expect actual
  639. '
  640. test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
  641. git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
  642. git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
  643. test_cmp actual reverse &&
  644. {
  645. grep -v patch.description <trailers | unfold &&
  646. echo
  647. } >expect &&
  648. test_cmp expect actual
  649. '
  650. test_expect_success '%(trailers) rejects unknown trailers arguments' '
  651. # error message cannot be checked under i18n
  652. cat >expect <<-EOF &&
  653. fatal: unknown %(trailers) argument: unsupported
  654. EOF
  655. test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
  656. test_i18ncmp expect actual
  657. '
  658. test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
  659. # error message cannot be checked under i18n
  660. cat >expect <<-EOF &&
  661. fatal: unknown %(trailers) argument: unsupported
  662. EOF
  663. test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
  664. test_i18ncmp expect actual
  665. '
  666. test_expect_success 'basic atom: head contents:trailers' '
  667. git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
  668. sanitize_pgp <actual >actual.clean &&
  669. # git for-each-ref ends with a blank line
  670. cat >expect <<-EOF &&
  671. $(cat trailers)
  672. EOF
  673. test_cmp expect actual.clean
  674. '
  675. test_expect_success 'trailer parsing not fooled by --- line' '
  676. git commit --allow-empty -F - <<-\EOF &&
  677. this is the subject
  678. This is the body. The message has a "---" line which would confuse a
  679. message+patch parser. But here we know we have only a commit message,
  680. so we get it right.
  681. trailer: wrong
  682. ---
  683. This is more body.
  684. trailer: right
  685. EOF
  686. {
  687. echo "trailer: right" &&
  688. echo
  689. } >expect &&
  690. git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
  691. test_cmp expect actual
  692. '
  693. test_expect_success 'Add symbolic ref for the following tests' '
  694. git symbolic-ref refs/heads/sym refs/heads/master
  695. '
  696. cat >expected <<EOF
  697. refs/heads/master
  698. EOF
  699. test_expect_success 'Verify usage of %(symref) atom' '
  700. git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
  701. test_cmp expected actual
  702. '
  703. cat >expected <<EOF
  704. heads/master
  705. EOF
  706. test_expect_success 'Verify usage of %(symref:short) atom' '
  707. git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
  708. test_cmp expected actual
  709. '
  710. cat >expected <<EOF
  711. master
  712. heads/master
  713. EOF
  714. test_expect_success 'Verify usage of %(symref:lstrip) atom' '
  715. git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
  716. git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
  717. test_cmp expected actual &&
  718. git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
  719. git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
  720. test_cmp expected actual
  721. '
  722. cat >expected <<EOF
  723. refs
  724. refs/heads
  725. EOF
  726. test_expect_success 'Verify usage of %(symref:rstrip) atom' '
  727. git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
  728. git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
  729. test_cmp expected actual
  730. '
  731. test_expect_success ':remotename and :remoteref' '
  732. git init remote-tests &&
  733. (
  734. cd remote-tests &&
  735. test_commit initial &&
  736. git remote add from fifth.coffee:blub &&
  737. git config branch.master.remote from &&
  738. git config branch.master.merge refs/heads/stable &&
  739. git remote add to southridge.audio:repo &&
  740. git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
  741. git config branch.master.pushRemote to &&
  742. for pair in "%(upstream)=refs/remotes/from/stable" \
  743. "%(upstream:remotename)=from" \
  744. "%(upstream:remoteref)=refs/heads/stable" \
  745. "%(push)=refs/remotes/to/pushed/master" \
  746. "%(push:remotename)=to" \
  747. "%(push:remoteref)=refs/heads/pushed/master"
  748. do
  749. echo "${pair#*=}" >expect &&
  750. git for-each-ref --format="${pair%=*}" \
  751. refs/heads/master >actual &&
  752. test_cmp expect actual
  753. done &&
  754. git branch push-simple &&
  755. git config branch.push-simple.pushRemote from &&
  756. actual="$(git for-each-ref \
  757. --format="%(push:remotename),%(push:remoteref)" \
  758. refs/heads/push-simple)" &&
  759. test from, = "$actual"
  760. )
  761. '
  762. test_expect_success 'for-each-ref --ignore-case ignores case' '
  763. git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
  764. test_must_be_empty actual &&
  765. echo refs/heads/master >expect &&
  766. git for-each-ref --format="%(refname)" --ignore-case \
  767. refs/heads/MASTER >actual &&
  768. test_cmp expect actual
  769. '
  770. test_done