Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Andy Parkins |
| 4 | # |
| 5 | |
| 6 | test_description='for-each-ref test' |
| 7 | |
| 8 | . ./test-lib.sh |
Kousik Sanagavarapu | 26c9c03 | 2023-06-04 23:52:47 +0530 | [diff] [blame] | 9 | GNUPGHOME_NOT_USED=$GNUPGHOME |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 10 | . "$TEST_DIRECTORY"/lib-gpg.sh |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 11 | . "$TEST_DIRECTORY"/lib-terminal.sh |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 12 | |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 13 | # Mon Jul 3 23:18:43 2006 +0000 |
| 14 | datestamp=1151968723 |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 15 | setdate_and_increment () { |
| 16 | GIT_COMMITTER_DATE="$datestamp +0200" |
| 17 | datestamp=$(expr "$datestamp" + 1) |
| 18 | GIT_AUTHOR_DATE="$datestamp +0200" |
| 19 | datestamp=$(expr "$datestamp" + 1) |
| 20 | export GIT_COMMITTER_DATE GIT_AUTHOR_DATE |
| 21 | } |
| 22 | |
René Scharfe | fbc6526 | 2023-12-12 18:04:55 +0100 | [diff] [blame] | 23 | test_object_file_size () { |
| 24 | oid=$(git rev-parse "$1") |
| 25 | path=".git/objects/$(test_oid_to_path $oid)" |
| 26 | test_file_size "$path" |
| 27 | } |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 28 | |
René Scharfe | fbc6526 | 2023-12-12 18:04:55 +0100 | [diff] [blame] | 29 | test_expect_success setup ' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 30 | # setup .mailmap |
| 31 | cat >.mailmap <<-EOF && |
| 32 | A Thor <athor@example.com> A U Thor <author@example.com> |
| 33 | C Mitter <cmitter@example.com> C O Mitter <committer@example.com> |
| 34 | EOF |
| 35 | |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 36 | setdate_and_increment && |
| 37 | echo "Using $datestamp" > one && |
| 38 | git add one && |
| 39 | git commit -m "Initial" && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 40 | git branch -M main && |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 41 | setdate_and_increment && |
Ramkumar Ramachandra | bc14796 | 2013-11-18 23:09:08 +0530 | [diff] [blame] | 42 | git tag -a -m "Tagging at $datestamp" testtag && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 43 | git update-ref refs/remotes/origin/main main && |
Jeff King | 8cae19d | 2009-04-07 03:09:39 -0400 | [diff] [blame] | 44 | git remote add origin nowhere && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 45 | git config branch.main.remote origin && |
| 46 | git config branch.main.merge refs/heads/main && |
Jeff King | 29bc885 | 2015-05-21 00:45:55 -0400 | [diff] [blame] | 47 | git remote add myfork elsewhere && |
| 48 | git config remote.pushdefault myfork && |
| 49 | git config push.default current |
Jeff King | 8cae19d | 2009-04-07 03:09:39 -0400 | [diff] [blame] | 50 | ' |
| 51 | |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 52 | test_atom () { |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 53 | case "$1" in |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 54 | head) ref=refs/heads/main ;; |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 55 | tag) ref=refs/tags/testtag ;; |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 56 | sym) ref=refs/heads/sym ;; |
Jeff King | 7140c22 | 2011-09-07 13:43:28 -0400 | [diff] [blame] | 57 | *) ref=$1 ;; |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 58 | esac |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 59 | format=$2 |
| 60 | test_do=test_expect_${4:-success} |
| 61 | |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 62 | printf '%s\n' "$3" >expected |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 63 | $test_do $PREREQ "basic atom: $ref $format" ' |
| 64 | git for-each-ref --format="%($format)" "$ref" >actual && |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 65 | sanitize_pgp <actual >actual.clean && |
| 66 | test_cmp expected actual.clean |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 67 | ' |
| 68 | |
Christian Couder | b6839fd | 2020-07-16 14:19:40 +0200 | [diff] [blame] | 69 | # Automatically test "contents:size" atom after testing "contents" |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 70 | if test "$format" = "contents" |
Christian Couder | b6839fd | 2020-07-16 14:19:40 +0200 | [diff] [blame] | 71 | then |
Đoàn Trần Công Danh | 597fa8c | 2021-08-21 08:36:33 +0700 | [diff] [blame] | 72 | # for commit leg, $3 is changed there |
| 73 | expect=$(printf '%s' "$3" | wc -c) |
Kousik Sanagavarapu | 04830eb | 2023-09-25 23:13:08 +0530 | [diff] [blame] | 74 | $test_do $PREREQ "basic atom: $ref contents:size" ' |
Đoàn Trần Công Danh | 597fa8c | 2021-08-21 08:36:33 +0700 | [diff] [blame] | 75 | type=$(git cat-file -t "$ref") && |
| 76 | case $type in |
| 77 | tag) |
| 78 | # We cannot use $3 as it expects sanitize_pgp to run |
Đoàn Trần Công Danh | 1549577 | 2021-08-21 08:36:34 +0700 | [diff] [blame] | 79 | git cat-file tag $ref >out && |
| 80 | expect=$(tail -n +6 out | wc -c) && |
| 81 | rm -f out ;; |
Đoàn Trần Công Danh | 597fa8c | 2021-08-21 08:36:33 +0700 | [diff] [blame] | 82 | tree | blob) |
| 83 | expect="" ;; |
| 84 | commit) |
| 85 | : "use the calculated expect" ;; |
| 86 | *) |
| 87 | BUG "unknown object type" ;; |
| 88 | esac && |
| 89 | # Leave $expect unquoted to lose possible leading whitespaces |
| 90 | echo $expect >expected && |
Christian Couder | b6839fd | 2020-07-16 14:19:40 +0200 | [diff] [blame] | 91 | git for-each-ref --format="%(contents:size)" "$ref" >actual && |
Alban Gruin | 3db796c | 2020-07-31 20:26:07 +0200 | [diff] [blame] | 92 | test_cmp expected actual |
Christian Couder | b6839fd | 2020-07-16 14:19:40 +0200 | [diff] [blame] | 93 | ' |
| 94 | fi |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 95 | } |
| 96 | |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 97 | hexlen=$(test_oid hexsz) |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 98 | |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 99 | test_atom head refname refs/heads/main |
| 100 | test_atom head refname: refs/heads/main |
| 101 | test_atom head refname:short main |
| 102 | test_atom head refname:lstrip=1 heads/main |
| 103 | test_atom head refname:lstrip=2 main |
| 104 | test_atom head refname:lstrip=-1 main |
| 105 | test_atom head refname:lstrip=-2 heads/main |
Karthik Nayak | 1a34728 | 2017-01-10 14:19:49 +0530 | [diff] [blame] | 106 | test_atom head refname:rstrip=1 refs/heads |
| 107 | test_atom head refname:rstrip=2 refs |
| 108 | test_atom head refname:rstrip=-1 refs |
| 109 | test_atom head refname:rstrip=-2 refs/heads |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 110 | test_atom head refname:strip=1 heads/main |
| 111 | test_atom head refname:strip=2 main |
| 112 | test_atom head refname:strip=-1 main |
| 113 | test_atom head refname:strip=-2 heads/main |
| 114 | test_atom head upstream refs/remotes/origin/main |
| 115 | test_atom head upstream:short origin/main |
| 116 | test_atom head upstream:lstrip=2 origin/main |
| 117 | test_atom head upstream:lstrip=-2 origin/main |
Karthik Nayak | 1a34728 | 2017-01-10 14:19:49 +0530 | [diff] [blame] | 118 | test_atom head upstream:rstrip=2 refs/remotes |
| 119 | test_atom head upstream:rstrip=-2 refs/remotes |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 120 | test_atom head upstream:strip=2 origin/main |
| 121 | test_atom head upstream:strip=-2 origin/main |
| 122 | test_atom head push refs/remotes/myfork/main |
| 123 | test_atom head push:short myfork/main |
| 124 | test_atom head push:lstrip=1 remotes/myfork/main |
| 125 | test_atom head push:lstrip=-1 main |
Karthik Nayak | 1a34728 | 2017-01-10 14:19:49 +0530 | [diff] [blame] | 126 | test_atom head push:rstrip=1 refs/remotes/myfork |
| 127 | test_atom head push:rstrip=-1 refs |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 128 | test_atom head push:strip=1 remotes/myfork/main |
| 129 | test_atom head push:strip=-1 main |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 130 | test_atom head objecttype commit |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 131 | test_atom head objectsize $((131 + hexlen)) |
René Scharfe | fbc6526 | 2023-12-12 18:04:55 +0100 | [diff] [blame] | 132 | test_atom head objectsize:disk $(test_object_file_size refs/heads/main) |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 133 | test_atom head deltabase $ZERO_OID |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 134 | test_atom head objectname $(git rev-parse refs/heads/main) |
| 135 | test_atom head objectname:short $(git rev-parse --short refs/heads/main) |
| 136 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) |
| 137 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) |
| 138 | test_atom head tree $(git rev-parse refs/heads/main^{tree}) |
| 139 | test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree}) |
| 140 | test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree}) |
| 141 | test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree}) |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 142 | test_atom head parent '' |
Hariom Verma | 26bc0aa | 2020-08-21 21:41:48 +0000 | [diff] [blame] | 143 | test_atom head parent:short '' |
| 144 | test_atom head parent:short=1 '' |
| 145 | test_atom head parent:short=10 '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 146 | test_atom head numparent 0 |
| 147 | test_atom head object '' |
| 148 | test_atom head type '' |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 149 | test_atom head raw "$(git cat-file commit refs/heads/main) |
| 150 | " |
Jeff King | b74cf64 | 2013-10-30 02:50:16 -0400 | [diff] [blame] | 151 | test_atom head '*objectname' '' |
| 152 | test_atom head '*objecttype' '' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 153 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 154 | test_atom head authorname 'A U Thor' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 155 | test_atom head authorname:mailmap 'A Thor' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 156 | test_atom head authoremail '<author@example.com>' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 157 | test_atom head authoremail:trim 'author@example.com' |
| 158 | test_atom head authoremail:localpart 'author' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 159 | test_atom head authoremail:trim,localpart 'author' |
| 160 | test_atom head authoremail:mailmap '<athor@example.com>' |
| 161 | test_atom head authoremail:mailmap,trim 'athor@example.com' |
| 162 | test_atom head authoremail:trim,mailmap 'athor@example.com' |
| 163 | test_atom head authoremail:mailmap,localpart 'athor' |
| 164 | test_atom head authoremail:localpart,mailmap 'athor' |
| 165 | test_atom head authoremail:mailmap,trim,localpart,mailmap,trim 'athor' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 166 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
| 167 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 168 | test_atom head committername 'C O Mitter' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 169 | test_atom head committername:mailmap 'C Mitter' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 170 | test_atom head committeremail '<committer@example.com>' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 171 | test_atom head committeremail:trim 'committer@example.com' |
| 172 | test_atom head committeremail:localpart 'committer' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 173 | test_atom head committeremail:localpart,trim 'committer' |
| 174 | test_atom head committeremail:mailmap '<cmitter@example.com>' |
| 175 | test_atom head committeremail:mailmap,trim 'cmitter@example.com' |
| 176 | test_atom head committeremail:trim,mailmap 'cmitter@example.com' |
| 177 | test_atom head committeremail:mailmap,localpart 'cmitter' |
| 178 | test_atom head committeremail:localpart,mailmap 'cmitter' |
| 179 | test_atom head committeremail:trim,mailmap,trim,trim,localpart 'cmitter' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 180 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 181 | test_atom head tag '' |
| 182 | test_atom head tagger '' |
| 183 | test_atom head taggername '' |
| 184 | test_atom head taggeremail '' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 185 | test_atom head taggeremail:trim '' |
| 186 | test_atom head taggeremail:localpart '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 187 | test_atom head taggerdate '' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 188 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
| 189 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 190 | test_atom head subject 'Initial' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 191 | test_atom head subject:sanitize 'Initial' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 192 | test_atom head contents:subject 'Initial' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 193 | test_atom head body '' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 194 | test_atom head contents:body '' |
| 195 | test_atom head contents:signature '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 196 | test_atom head contents 'Initial |
| 197 | ' |
Ramkumar Ramachandra | 7a48b83 | 2013-11-18 23:09:10 +0530 | [diff] [blame] | 198 | test_atom head HEAD '*' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 199 | |
| 200 | test_atom tag refname refs/tags/testtag |
Jeff King | 1d094db | 2016-01-24 18:08:18 -0500 | [diff] [blame] | 201 | test_atom tag refname:short testtag |
Jeff King | 8cae19d | 2009-04-07 03:09:39 -0400 | [diff] [blame] | 202 | test_atom tag upstream '' |
Jeff King | 29bc885 | 2015-05-21 00:45:55 -0400 | [diff] [blame] | 203 | test_atom tag push '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 204 | test_atom tag objecttype tag |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 205 | test_atom tag objectsize $((114 + hexlen)) |
René Scharfe | fbc6526 | 2023-12-12 18:04:55 +0100 | [diff] [blame] | 206 | test_atom tag objectsize:disk $(test_object_file_size refs/tags/testtag) |
| 207 | test_atom tag '*objectsize:disk' $(test_object_file_size refs/heads/main) |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 208 | test_atom tag deltabase $ZERO_OID |
| 209 | test_atom tag '*deltabase' $ZERO_OID |
Ramkumar Ramachandra | 189a546 | 2013-11-18 23:09:09 +0530 | [diff] [blame] | 210 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
Jeff King | 1d094db | 2016-01-24 18:08:18 -0500 | [diff] [blame] | 211 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 212 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) |
| 213 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 214 | test_atom tag tree '' |
Hariom Verma | 837adb1 | 2020-08-21 21:41:47 +0000 | [diff] [blame] | 215 | test_atom tag tree:short '' |
| 216 | test_atom tag tree:short=1 '' |
| 217 | test_atom tag tree:short=10 '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 218 | test_atom tag parent '' |
Hariom Verma | 26bc0aa | 2020-08-21 21:41:48 +0000 | [diff] [blame] | 219 | test_atom tag parent:short '' |
| 220 | test_atom tag parent:short=1 '' |
| 221 | test_atom tag parent:short=10 '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 222 | test_atom tag numparent '' |
Ramkumar Ramachandra | 189a546 | 2013-11-18 23:09:09 +0530 | [diff] [blame] | 223 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 224 | test_atom tag type 'commit' |
brian m. carlson | 1f5f8f3 | 2020-02-22 20:17:32 +0000 | [diff] [blame] | 225 | test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{}) |
Jeff King | b74cf64 | 2013-10-30 02:50:16 -0400 | [diff] [blame] | 226 | test_atom tag '*objecttype' 'commit' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 227 | test_atom tag author '' |
| 228 | test_atom tag authorname '' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 229 | test_atom tag authorname:mailmap '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 230 | test_atom tag authoremail '' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 231 | test_atom tag authoremail:trim '' |
| 232 | test_atom tag authoremail:localpart '' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 233 | test_atom tag authoremail:trim,localpart '' |
| 234 | test_atom tag authoremail:mailmap '' |
| 235 | test_atom tag authoremail:mailmap,trim '' |
| 236 | test_atom tag authoremail:trim,mailmap '' |
| 237 | test_atom tag authoremail:mailmap,localpart '' |
| 238 | test_atom tag authoremail:localpart,mailmap '' |
| 239 | test_atom tag authoremail:mailmap,trim,localpart,mailmap,trim '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 240 | test_atom tag authordate '' |
| 241 | test_atom tag committer '' |
| 242 | test_atom tag committername '' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 243 | test_atom tag committername:mailmap '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 244 | test_atom tag committeremail '' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 245 | test_atom tag committeremail:trim '' |
| 246 | test_atom tag committeremail:localpart '' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 247 | test_atom tag committeremail:localpart,trim '' |
| 248 | test_atom tag committeremail:mailmap '' |
| 249 | test_atom tag committeremail:mailmap,trim '' |
| 250 | test_atom tag committeremail:trim,mailmap '' |
| 251 | test_atom tag committeremail:mailmap,localpart '' |
| 252 | test_atom tag committeremail:localpart,mailmap '' |
| 253 | test_atom tag committeremail:trim,mailmap,trim,trim,localpart '' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 254 | test_atom tag committerdate '' |
| 255 | test_atom tag tag 'testtag' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 256 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 257 | test_atom tag taggername 'C O Mitter' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 258 | test_atom tag taggername:mailmap 'C Mitter' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 259 | test_atom tag taggeremail '<committer@example.com>' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 260 | test_atom tag taggeremail:trim 'committer@example.com' |
| 261 | test_atom tag taggeremail:localpart 'committer' |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 262 | test_atom tag taggeremail:trim,localpart 'committer' |
| 263 | test_atom tag taggeremail:mailmap '<cmitter@example.com>' |
| 264 | test_atom tag taggeremail:mailmap,trim 'cmitter@example.com' |
| 265 | test_atom tag taggeremail:trim,mailmap 'cmitter@example.com' |
| 266 | test_atom tag taggeremail:mailmap,localpart 'cmitter' |
| 267 | test_atom tag taggeremail:localpart,mailmap 'cmitter' |
| 268 | test_atom tag taggeremail:trim,mailmap,trim,localpart,localpart 'cmitter' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 269 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
| 270 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' |
| 271 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' |
| 272 | test_atom tag subject 'Tagging at 1151968727' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 273 | test_atom tag subject:sanitize 'Tagging-at-1151968727' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 274 | test_atom tag contents:subject 'Tagging at 1151968727' |
Jeff King | d2bf48d | 2008-06-26 04:08:41 -0400 | [diff] [blame] | 275 | test_atom tag body '' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 276 | test_atom tag contents:body '' |
| 277 | test_atom tag contents:signature '' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 278 | test_atom tag contents 'Tagging at 1151968727 |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 279 | ' |
Ramkumar Ramachandra | 7a48b83 | 2013-11-18 23:09:10 +0530 | [diff] [blame] | 280 | test_atom tag HEAD ' ' |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 281 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 282 | test_expect_success 'basic atom: refs/tags/testtag *raw' ' |
| 283 | git cat-file commit refs/tags/testtag^{} >expected && |
| 284 | git for-each-ref --format="%(*raw)" refs/tags/testtag >actual && |
| 285 | sanitize_pgp <expected >expected.clean && |
| 286 | echo >>expected.clean && |
| 287 | sanitize_pgp <actual >actual.clean && |
| 288 | test_cmp expected.clean actual.clean |
| 289 | ' |
| 290 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 291 | test_expect_success 'Check invalid atoms names are errors' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 292 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 293 | ' |
| 294 | |
| 295 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 296 | git for-each-ref --format="%(authordate)" refs/heads && |
| 297 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && |
| 298 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && |
| 299 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 300 | ' |
| 301 | |
| 302 | test_expect_success 'Check valid format specifiers for date fields' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 303 | git for-each-ref --format="%(authordate:default)" refs/heads && |
| 304 | git for-each-ref --format="%(authordate:relative)" refs/heads && |
| 305 | git for-each-ref --format="%(authordate:short)" refs/heads && |
| 306 | git for-each-ref --format="%(authordate:local)" refs/heads && |
| 307 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && |
| 308 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 309 | ' |
| 310 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 311 | test_expect_success 'Check invalid format specifiers are errors' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 312 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 313 | ' |
| 314 | |
Karthik Nayak | 42d0eb0 | 2017-01-10 14:19:37 +0530 | [diff] [blame] | 315 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
| 316 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && |
| 317 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && |
| 318 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" |
| 319 | ' |
| 320 | |
Kousik Sanagavarapu | 0144f0d | 2023-09-25 23:13:09 +0530 | [diff] [blame] | 321 | test_bad_atom () { |
| 322 | case "$1" in |
| 323 | head) ref=refs/heads/main ;; |
| 324 | tag) ref=refs/tags/testtag ;; |
| 325 | sym) ref=refs/heads/sym ;; |
| 326 | *) ref=$1 ;; |
| 327 | esac |
| 328 | format=$2 |
| 329 | test_do=test_expect_${4:-success} |
| 330 | |
| 331 | printf '%s\n' "$3" >expect |
| 332 | $test_do $PREREQ "err basic atom: $ref $format" ' |
| 333 | test_must_fail git for-each-ref \ |
| 334 | --format="%($format)" "$ref" 2>error && |
| 335 | test_cmp expect error |
| 336 | ' |
| 337 | } |
| 338 | |
| 339 | test_bad_atom head 'authoremail:foo' \ |
| 340 | 'fatal: unrecognized %(authoremail) argument: foo' |
| 341 | |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 342 | test_bad_atom head 'authoremail:mailmap,trim,bar' \ |
| 343 | 'fatal: unrecognized %(authoremail) argument: bar' |
| 344 | |
| 345 | test_bad_atom head 'authoremail:trim,' \ |
| 346 | 'fatal: unrecognized %(authoremail) argument: ' |
| 347 | |
| 348 | test_bad_atom head 'authoremail:mailmaptrim' \ |
| 349 | 'fatal: unrecognized %(authoremail) argument: trim' |
| 350 | |
| 351 | test_bad_atom head 'committeremail: ' \ |
| 352 | 'fatal: unrecognized %(committeremail) argument: ' |
| 353 | |
| 354 | test_bad_atom head 'committeremail: trim,foo' \ |
| 355 | 'fatal: unrecognized %(committeremail) argument: trim,foo' |
| 356 | |
| 357 | test_bad_atom head 'committeremail:mailmap,localpart ' \ |
| 358 | 'fatal: unrecognized %(committeremail) argument: ' |
| 359 | |
| 360 | test_bad_atom head 'committeremail:trim_localpart' \ |
| 361 | 'fatal: unrecognized %(committeremail) argument: _localpart' |
| 362 | |
| 363 | test_bad_atom head 'committeremail:localpart,,,trim' \ |
| 364 | 'fatal: unrecognized %(committeremail) argument: ,,trim' |
| 365 | |
| 366 | test_bad_atom tag 'taggeremail:mailmap,trim, foo ' \ |
| 367 | 'fatal: unrecognized %(taggeremail) argument: foo ' |
| 368 | |
| 369 | test_bad_atom tag 'taggeremail:trim,localpart,' \ |
| 370 | 'fatal: unrecognized %(taggeremail) argument: ' |
| 371 | |
| 372 | test_bad_atom tag 'taggeremail:mailmap;localpart trim' \ |
| 373 | 'fatal: unrecognized %(taggeremail) argument: ;localpart trim' |
| 374 | |
Kousik Sanagavarapu | 0144f0d | 2023-09-25 23:13:09 +0530 | [diff] [blame] | 375 | test_bad_atom tag 'taggeremail:localpart trim' \ |
Kousik Sanagavarapu | a3d2e83 | 2023-09-25 23:13:10 +0530 | [diff] [blame] | 376 | 'fatal: unrecognized %(taggeremail) argument: trim' |
| 377 | |
| 378 | test_bad_atom tag 'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \ |
| 379 | 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim' |
Kousik Sanagavarapu | 0144f0d | 2023-09-25 23:13:09 +0530 | [diff] [blame] | 380 | |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 381 | test_date () { |
| 382 | f=$1 && |
| 383 | committer_date=$2 && |
| 384 | author_date=$3 && |
| 385 | tagger_date=$4 && |
| 386 | cat >expected <<-EOF && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 387 | 'refs/heads/main' '$committer_date' '$author_date' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 388 | 'refs/tags/testtag' '$tagger_date' |
| 389 | EOF |
| 390 | ( |
| 391 | git for-each-ref --shell \ |
| 392 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ |
| 393 | refs/heads && |
| 394 | git for-each-ref --shell \ |
| 395 | --format="%(refname) %(taggerdate${f:+:$f})" \ |
| 396 | refs/tags |
| 397 | ) >actual && |
| 398 | test_cmp expected actual |
| 399 | } |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 400 | |
| 401 | test_expect_success 'Check unformatted date fields output' ' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 402 | test_date "" \ |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 403 | "Tue Jul 4 01:18:43 2006 +0200" \ |
| 404 | "Tue Jul 4 01:18:44 2006 +0200" \ |
| 405 | "Tue Jul 4 01:18:45 2006 +0200" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 406 | ' |
| 407 | |
| 408 | test_expect_success 'Check format "default" formatted date fields output' ' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 409 | test_date default \ |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 410 | "Tue Jul 4 01:18:43 2006 +0200" \ |
| 411 | "Tue Jul 4 01:18:44 2006 +0200" \ |
| 412 | "Tue Jul 4 01:18:45 2006 +0200" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 413 | ' |
| 414 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 415 | test_expect_success 'Check format "default-local" date fields output' ' |
| 416 | 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" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 417 | ' |
| 418 | |
| 419 | # Don't know how to do relative check because I can't know when this script |
| 420 | # is going to be run and can't fake the current time to git, and hence can't |
| 421 | # provide expected output. Instead, I'll just make sure that "relative" |
| 422 | # doesn't exit in error |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 423 | test_expect_success 'Check format "relative" date fields output' ' |
| 424 | f=relative && |
| 425 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && |
| 426 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual |
| 427 | ' |
| 428 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 429 | # We just check that this is the same as "relative" for now. |
| 430 | test_expect_success 'Check format "relative-local" date fields output' ' |
| 431 | test_date relative-local \ |
| 432 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ |
| 433 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ |
| 434 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" |
| 435 | ' |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 436 | |
| 437 | test_expect_success 'Check format "short" date fields output' ' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 438 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 439 | ' |
| 440 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 441 | test_expect_success 'Check format "short-local" date fields output' ' |
| 442 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 |
| 443 | ' |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 444 | |
| 445 | test_expect_success 'Check format "local" date fields output' ' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 446 | test_date local \ |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 447 | "Mon Jul 3 23:18:43 2006" \ |
| 448 | "Mon Jul 3 23:18:44 2006" \ |
| 449 | "Mon Jul 3 23:18:45 2006" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 450 | ' |
| 451 | |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 452 | test_expect_success 'Check format "iso8601" date fields output' ' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 453 | test_date iso8601 \ |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 454 | "2006-07-04 01:18:43 +0200" \ |
| 455 | "2006-07-04 01:18:44 +0200" \ |
| 456 | "2006-07-04 01:18:45 +0200" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 457 | ' |
| 458 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 459 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
| 460 | 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" |
| 461 | ' |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 462 | |
| 463 | test_expect_success 'Check format "rfc2822" date fields output' ' |
John Keeping | f95cecf | 2015-09-03 22:48:56 +0100 | [diff] [blame] | 464 | test_date rfc2822 \ |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 465 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
| 466 | "Tue, 4 Jul 2006 01:18:44 +0200" \ |
| 467 | "Tue, 4 Jul 2006 01:18:45 +0200" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 468 | ' |
| 469 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 470 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
| 471 | 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" |
| 472 | ' |
| 473 | |
John Keeping | f3c1ba5 | 2015-09-03 22:48:57 +0100 | [diff] [blame] | 474 | test_expect_success 'Check format "raw" date fields output' ' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 475 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
John Keeping | f3c1ba5 | 2015-09-03 22:48:57 +0100 | [diff] [blame] | 476 | ' |
| 477 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 478 | test_expect_success 'Check format "raw-local" date fields output' ' |
| 479 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 480 | ' |
| 481 | |
Jeff King | aa1462c | 2015-06-25 12:55:45 -0400 | [diff] [blame] | 482 | test_expect_success 'Check format of strftime date fields' ' |
John Keeping | db7bae2 | 2015-09-03 22:49:00 +0100 | [diff] [blame] | 483 | echo "my date is 2006-07-04" >expected && |
Jeff King | aa1462c | 2015-06-25 12:55:45 -0400 | [diff] [blame] | 484 | git for-each-ref \ |
| 485 | --format="%(authordate:format:my date is %Y-%m-%d)" \ |
| 486 | refs/heads >actual && |
| 487 | test_cmp expected actual |
| 488 | ' |
| 489 | |
John Keeping | 99264e9 | 2015-09-03 22:49:01 +0100 | [diff] [blame] | 490 | test_expect_success 'Check format of strftime-local date fields' ' |
| 491 | echo "my date is 2006-07-03" >expected && |
| 492 | git for-each-ref \ |
| 493 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ |
| 494 | refs/heads >actual && |
| 495 | test_cmp expected actual |
| 496 | ' |
| 497 | |
Jeff King | e4f031e | 2015-06-30 09:26:53 -0400 | [diff] [blame] | 498 | test_expect_success 'exercise strftime with odd fields' ' |
| 499 | echo >expected && |
| 500 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && |
| 501 | test_cmp expected actual && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 502 | long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" && |
Jeff King | e4f031e | 2015-06-30 09:26:53 -0400 | [diff] [blame] | 503 | echo $long >expected && |
| 504 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && |
| 505 | test_cmp expected actual |
| 506 | ' |
| 507 | |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 508 | cat >expected <<\EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 509 | refs/heads/main |
| 510 | refs/remotes/origin/main |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 511 | refs/tags/testtag |
| 512 | EOF |
| 513 | |
| 514 | test_expect_success 'Verify ascending sort' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 515 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 516 | test_cmp expected actual |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 517 | ' |
| 518 | |
| 519 | |
| 520 | cat >expected <<\EOF |
| 521 | refs/tags/testtag |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 522 | refs/remotes/origin/main |
| 523 | refs/heads/main |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 524 | EOF |
| 525 | |
| 526 | test_expect_success 'Verify descending sort' ' |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 527 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 528 | test_cmp expected actual |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 529 | ' |
| 530 | |
Junio C Hamano | 98e7ab6 | 2021-10-20 12:23:53 -0700 | [diff] [blame] | 531 | test_expect_success 'Give help even with invalid sort atoms' ' |
| 532 | test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 && |
| 533 | grep "^usage: git for-each-ref" actual |
| 534 | ' |
| 535 | |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 536 | cat >expected <<\EOF |
Taylor Blau | b31e268 | 2019-06-26 17:41:48 -0500 | [diff] [blame] | 537 | refs/tags/testtag |
| 538 | refs/tags/testtag-2 |
| 539 | EOF |
| 540 | |
| 541 | test_expect_success 'exercise patterns with prefixes' ' |
| 542 | git tag testtag-2 && |
| 543 | test_when_finished "git tag -d testtag-2" && |
| 544 | git for-each-ref --format="%(refname)" \ |
| 545 | refs/tags/testtag refs/tags/testtag-2 >actual && |
| 546 | test_cmp expected actual |
| 547 | ' |
| 548 | |
| 549 | cat >expected <<\EOF |
| 550 | refs/tags/testtag |
| 551 | refs/tags/testtag-2 |
| 552 | EOF |
| 553 | |
| 554 | test_expect_success 'exercise glob patterns with prefixes' ' |
| 555 | git tag testtag-2 && |
| 556 | test_when_finished "git tag -d testtag-2" && |
| 557 | git for-each-ref --format="%(refname)" \ |
| 558 | refs/tags/testtag "refs/tags/testtag-*" >actual && |
| 559 | test_cmp expected actual |
| 560 | ' |
| 561 | |
| 562 | cat >expected <<\EOF |
Taylor Blau | 8255dd8 | 2023-07-10 17:12:19 -0400 | [diff] [blame] | 563 | refs/tags/bar |
| 564 | refs/tags/baz |
| 565 | refs/tags/testtag |
| 566 | EOF |
| 567 | |
| 568 | test_expect_success 'exercise patterns with prefix exclusions' ' |
| 569 | for tag in foo/one foo/two foo/three bar baz |
| 570 | do |
| 571 | git tag "$tag" || return 1 |
| 572 | done && |
| 573 | test_when_finished "git tag -d foo/one foo/two foo/three bar baz" && |
| 574 | git for-each-ref --format="%(refname)" \ |
| 575 | refs/tags/ --exclude=refs/tags/foo >actual && |
| 576 | test_cmp expected actual |
| 577 | ' |
| 578 | |
| 579 | cat >expected <<\EOF |
| 580 | refs/tags/bar |
| 581 | refs/tags/baz |
| 582 | refs/tags/foo/one |
| 583 | refs/tags/testtag |
| 584 | EOF |
| 585 | |
| 586 | test_expect_success 'exercise patterns with pattern exclusions' ' |
| 587 | for tag in foo/one foo/two foo/three bar baz |
| 588 | do |
| 589 | git tag "$tag" || return 1 |
| 590 | done && |
| 591 | test_when_finished "git tag -d foo/one foo/two foo/three bar baz" && |
| 592 | git for-each-ref --format="%(refname)" \ |
| 593 | refs/tags/ --exclude="refs/tags/foo/t*" >actual && |
| 594 | test_cmp expected actual |
| 595 | ' |
| 596 | |
| 597 | cat >expected <<\EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 598 | 'refs/heads/main' |
| 599 | 'refs/remotes/origin/main' |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 600 | 'refs/tags/testtag' |
| 601 | EOF |
| 602 | |
| 603 | test_expect_success 'Quoting style: shell' ' |
| 604 | git for-each-ref --shell --format="%(refname)" >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 605 | test_cmp expected actual |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 606 | ' |
| 607 | |
| 608 | test_expect_success 'Quoting style: perl' ' |
| 609 | git for-each-ref --perl --format="%(refname)" >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 610 | test_cmp expected actual |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 611 | ' |
| 612 | |
| 613 | test_expect_success 'Quoting style: python' ' |
| 614 | git for-each-ref --python --format="%(refname)" >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 615 | test_cmp expected actual |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 616 | ' |
| 617 | |
| 618 | cat >expected <<\EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 619 | "refs/heads/main" |
| 620 | "refs/remotes/origin/main" |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 621 | "refs/tags/testtag" |
| 622 | EOF |
| 623 | |
| 624 | test_expect_success 'Quoting style: tcl' ' |
| 625 | git for-each-ref --tcl --format="%(refname)" >actual && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 626 | test_cmp expected actual |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 627 | ' |
| 628 | |
| 629 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do |
| 630 | test_expect_success "more than one quoting style: $i" " |
SZEDER Gábor | 2708ef4 | 2018-02-13 01:36:01 +0100 | [diff] [blame] | 631 | test_must_fail git for-each-ref $i 2>err && |
| 632 | grep '^error: more than one quoting style' err |
Johannes Sixt | c9ecf4f | 2007-12-06 13:24:39 +0100 | [diff] [blame] | 633 | " |
| 634 | done |
Lars Hjemli | c899a57 | 2007-11-10 17:47:54 +0100 | [diff] [blame] | 635 | |
Ramkumar Ramachandra | b28061c | 2013-11-18 23:09:11 +0530 | [diff] [blame] | 636 | test_expect_success 'setup for upstream:track[short]' ' |
| 637 | test_commit two |
| 638 | ' |
| 639 | |
Jeff King | 1d094db | 2016-01-24 18:08:18 -0500 | [diff] [blame] | 640 | test_atom head upstream:track '[ahead 1]' |
| 641 | test_atom head upstream:trackshort '>' |
Karthik Nayak | 7743fcc | 2017-01-10 14:19:41 +0530 | [diff] [blame] | 642 | test_atom head upstream:track,nobracket 'ahead 1' |
| 643 | test_atom head upstream:nobracket,track 'ahead 1' |
Damien Robert | c646d09 | 2019-04-16 14:16:46 +0200 | [diff] [blame] | 644 | |
| 645 | test_expect_success 'setup for push:track[short]' ' |
| 646 | test_commit third && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 647 | git update-ref refs/remotes/myfork/main main && |
| 648 | git reset main~1 |
Damien Robert | c646d09 | 2019-04-16 14:16:46 +0200 | [diff] [blame] | 649 | ' |
| 650 | |
| 651 | test_atom head push:track '[behind 1]' |
| 652 | test_atom head push:trackshort '<' |
Ramkumar Ramachandra | b28061c | 2013-11-18 23:09:11 +0530 | [diff] [blame] | 653 | |
| 654 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' |
| 655 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && |
| 656 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null |
| 657 | ' |
| 658 | |
Raphael Kubo da Costa | b6160d9 | 2015-01-05 11:58:55 +0200 | [diff] [blame] | 659 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
| 660 | cat >expected <<-\EOF && |
Karthik Nayak | ffd921d | 2017-01-10 14:19:40 +0530 | [diff] [blame] | 661 | [gone] |
Raphael Kubo da Costa | b6160d9 | 2015-01-05 11:58:55 +0200 | [diff] [blame] | 662 | |
| 663 | EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 664 | test_when_finished "git config branch.main.merge refs/heads/main" && |
| 665 | git config branch.main.merge refs/heads/does-not-exist && |
Raphael Kubo da Costa | b6160d9 | 2015-01-05 11:58:55 +0200 | [diff] [blame] | 666 | git for-each-ref \ |
| 667 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ |
| 668 | refs/heads >actual && |
| 669 | test_cmp expected actual |
| 670 | ' |
| 671 | |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 672 | test_expect_success 'Check for invalid refname format' ' |
| 673 | test_must_fail git for-each-ref --format="%(refname:INVALID)" |
| 674 | ' |
| 675 | |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 676 | test_expect_success 'set up color tests' ' |
| 677 | cat >expected.color <<-EOF && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 678 | $(git rev-parse --short refs/heads/main) <GREEN>main<RESET> |
| 679 | $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET> |
| 680 | $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET> |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 681 | $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> |
Damien Robert | c646d09 | 2019-04-16 14:16:46 +0200 | [diff] [blame] | 682 | $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 683 | $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> |
| 684 | EOF |
| 685 | sed "s/<[^>]*>//g" <expected.color >expected.bare && |
| 686 | color_format="%(objectname:short) %(color:green)%(refname:short)" |
| 687 | ' |
Ramkumar Ramachandra | fddb74c | 2013-11-18 23:09:12 +0530 | [diff] [blame] | 688 | |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 689 | test_expect_success TTY '%(color) shows color with a tty' ' |
Jeff King | e433749 | 2017-10-03 09:39:34 -0400 | [diff] [blame] | 690 | test_terminal git for-each-ref --format="$color_format" >actual.raw && |
Jeff King | 097b681 | 2017-07-13 10:58:41 -0400 | [diff] [blame] | 691 | test_decode_color <actual.raw >actual && |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 692 | test_cmp expected.color actual |
| 693 | ' |
| 694 | |
| 695 | test_expect_success '%(color) does not show color without tty' ' |
| 696 | TERM=vt100 git for-each-ref --format="$color_format" >actual && |
| 697 | test_cmp expected.bare actual |
| 698 | ' |
| 699 | |
Jeff King | 0c88bf5 | 2017-10-03 09:45:47 -0400 | [diff] [blame] | 700 | test_expect_success '--color can override tty check' ' |
| 701 | git for-each-ref --color --format="$color_format" >actual.raw && |
Jeff King | 11b087a | 2017-07-13 11:09:32 -0400 | [diff] [blame] | 702 | test_decode_color <actual.raw >actual && |
| 703 | test_cmp expected.color actual |
Ramkumar Ramachandra | fddb74c | 2013-11-18 23:09:12 +0530 | [diff] [blame] | 704 | ' |
| 705 | |
Jeff King | b521fd1 | 2017-10-13 13:26:02 -0400 | [diff] [blame] | 706 | test_expect_success 'color.ui=always does not override tty check' ' |
| 707 | git -c color.ui=always for-each-ref --format="$color_format" >actual && |
| 708 | test_cmp expected.bare actual |
| 709 | ' |
| 710 | |
Kousik Sanagavarapu | f5d18f8 | 2023-07-23 21:49:59 +0530 | [diff] [blame] | 711 | test_expect_success 'setup for describe atom tests' ' |
| 712 | git init -b master describe-repo && |
| 713 | ( |
| 714 | cd describe-repo && |
| 715 | |
| 716 | test_commit --no-tag one && |
| 717 | git tag tagone && |
| 718 | |
| 719 | test_commit --no-tag two && |
| 720 | git tag -a -m "tag two" tagtwo |
| 721 | ) |
| 722 | ' |
| 723 | |
| 724 | test_expect_success 'describe atom vs git describe' ' |
| 725 | ( |
| 726 | cd describe-repo && |
| 727 | |
| 728 | git for-each-ref --format="%(objectname)" \ |
| 729 | refs/tags/ >obj && |
| 730 | while read hash |
| 731 | do |
| 732 | if desc=$(git describe $hash) |
| 733 | then |
| 734 | : >expect-contains-good |
| 735 | else |
| 736 | : >expect-contains-bad |
| 737 | fi && |
| 738 | echo "$hash $desc" || return 1 |
| 739 | done <obj >expect && |
| 740 | test_path_exists expect-contains-good && |
| 741 | test_path_exists expect-contains-bad && |
| 742 | |
| 743 | git for-each-ref --format="%(objectname) %(describe)" \ |
| 744 | refs/tags/ >actual 2>err && |
| 745 | test_cmp expect actual && |
| 746 | test_must_be_empty err |
| 747 | ) |
| 748 | ' |
| 749 | |
| 750 | test_expect_success 'describe:tags vs describe --tags' ' |
| 751 | ( |
| 752 | cd describe-repo && |
| 753 | git describe --tags >expect && |
| 754 | git for-each-ref --format="%(describe:tags)" \ |
| 755 | refs/heads/master >actual && |
| 756 | test_cmp expect actual |
| 757 | ) |
| 758 | ' |
| 759 | |
| 760 | test_expect_success 'describe:abbrev=... vs describe --abbrev=...' ' |
| 761 | ( |
| 762 | cd describe-repo && |
| 763 | |
| 764 | # Case 1: We have commits between HEAD and the most |
| 765 | # recent tag reachable from it |
| 766 | test_commit --no-tag file && |
| 767 | git describe --abbrev=14 >expect && |
| 768 | git for-each-ref --format="%(describe:abbrev=14)" \ |
| 769 | refs/heads/master >actual && |
| 770 | test_cmp expect actual && |
| 771 | |
| 772 | # Make sure the hash used is atleast 14 digits long |
| 773 | sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart && |
| 774 | test 15 -le $(wc -c <hexpart) && |
| 775 | |
| 776 | # Case 2: We have a tag at HEAD, describe directly gives |
| 777 | # the name of the tag |
| 778 | git tag -a -m tagged tagname && |
| 779 | git describe --abbrev=14 >expect && |
| 780 | git for-each-ref --format="%(describe:abbrev=14)" \ |
| 781 | refs/heads/master >actual && |
| 782 | test_cmp expect actual && |
| 783 | test tagname = $(cat actual) |
| 784 | ) |
| 785 | ' |
| 786 | |
| 787 | test_expect_success 'describe:match=... vs describe --match ...' ' |
| 788 | ( |
| 789 | cd describe-repo && |
| 790 | git tag -a -m "tag foo" tag-foo && |
| 791 | git describe --match "*-foo" >expect && |
| 792 | git for-each-ref --format="%(describe:match="*-foo")" \ |
| 793 | refs/heads/master >actual && |
| 794 | test_cmp expect actual |
| 795 | ) |
| 796 | ' |
| 797 | |
| 798 | test_expect_success 'describe:exclude:... vs describe --exclude ...' ' |
| 799 | ( |
| 800 | cd describe-repo && |
| 801 | git tag -a -m "tag bar" tag-bar && |
| 802 | git describe --exclude "*-bar" >expect && |
| 803 | git for-each-ref --format="%(describe:exclude="*-bar")" \ |
| 804 | refs/heads/master >actual && |
| 805 | test_cmp expect actual |
| 806 | ) |
| 807 | ' |
| 808 | |
| 809 | test_expect_success 'deref with describe atom' ' |
| 810 | ( |
| 811 | cd describe-repo && |
| 812 | cat >expect <<-\EOF && |
| 813 | |
| 814 | tagname |
| 815 | tagname |
| 816 | tagname |
| 817 | |
| 818 | tagtwo |
| 819 | EOF |
| 820 | git for-each-ref --format="%(*describe)" >actual && |
| 821 | test_cmp expect actual |
| 822 | ) |
| 823 | ' |
| 824 | |
| 825 | test_expect_success 'err on bad describe atom arg' ' |
| 826 | ( |
| 827 | cd describe-repo && |
| 828 | |
| 829 | # The bad arg is the only arg passed to describe atom |
| 830 | cat >expect <<-\EOF && |
| 831 | fatal: unrecognized %(describe) argument: baz |
| 832 | EOF |
| 833 | test_must_fail git for-each-ref --format="%(describe:baz)" \ |
| 834 | refs/heads/master 2>actual && |
| 835 | test_cmp expect actual && |
| 836 | |
| 837 | # The bad arg is in the middle of the option string |
| 838 | # passed to the describe atom |
| 839 | cat >expect <<-\EOF && |
| 840 | fatal: unrecognized %(describe) argument: qux=1,abbrev=14 |
| 841 | EOF |
| 842 | test_must_fail git for-each-ref \ |
| 843 | --format="%(describe:tags,qux=1,abbrev=14)" \ |
| 844 | ref/heads/master 2>actual && |
| 845 | test_cmp expect actual |
| 846 | ) |
| 847 | ' |
| 848 | |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 849 | cat >expected <<\EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 850 | heads/main |
| 851 | tags/main |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 852 | EOF |
| 853 | |
Bert Wesarg | 2bb9816 | 2009-04-13 12:25:47 +0200 | [diff] [blame] | 854 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
| 855 | git config --bool core.warnambiguousrefs true && |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 856 | git checkout -b newtag && |
| 857 | echo "Using $datestamp" > one && |
| 858 | git add one && |
| 859 | git commit -m "Branch" && |
| 860 | setdate_and_increment && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 861 | git tag -m "Tagging at $datestamp" main && |
| 862 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 863 | test_cmp expected actual |
| 864 | ' |
| 865 | |
| 866 | cat >expected <<\EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 867 | heads/main |
| 868 | main |
Bert Wesarg | 2bb9816 | 2009-04-13 12:25:47 +0200 | [diff] [blame] | 869 | EOF |
| 870 | |
| 871 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' |
| 872 | git config --bool core.warnambiguousrefs false && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 873 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && |
Bert Wesarg | 2bb9816 | 2009-04-13 12:25:47 +0200 | [diff] [blame] | 874 | test_cmp expected actual |
| 875 | ' |
| 876 | |
| 877 | cat >expected <<\EOF |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 878 | heads/ambiguous |
| 879 | ambiguous |
| 880 | EOF |
| 881 | |
Bert Wesarg | 2bb9816 | 2009-04-13 12:25:47 +0200 | [diff] [blame] | 882 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 883 | git checkout main && |
Bert Wesarg | 7d66f21 | 2008-09-05 23:16:23 +0200 | [diff] [blame] | 884 | git tag ambiguous testtag^0 && |
| 885 | git branch ambiguous testtag^0 && |
| 886 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && |
| 887 | test_cmp expected actual |
| 888 | ' |
| 889 | |
Mischa POSLAWSKY | 8b3f33e | 2019-08-17 23:51:07 +0200 | [diff] [blame] | 890 | test_expect_success 'create tag without tagger' ' |
| 891 | git tag -a -m "Broken tag" taggerless && |
| 892 | git tag -f taggerless $(git cat-file tag taggerless | |
| 893 | sed -e "/^tagger /d" | |
Jeff King | 34959d8 | 2023-01-18 15:41:56 -0500 | [diff] [blame] | 894 | git hash-object --literally --stdin -w -t tag) |
Mischa POSLAWSKY | 8b3f33e | 2019-08-17 23:51:07 +0200 | [diff] [blame] | 895 | ' |
| 896 | |
| 897 | test_atom refs/tags/taggerless type 'commit' |
| 898 | test_atom refs/tags/taggerless tag 'taggerless' |
| 899 | test_atom refs/tags/taggerless tagger '' |
| 900 | test_atom refs/tags/taggerless taggername '' |
| 901 | test_atom refs/tags/taggerless taggeremail '' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 902 | test_atom refs/tags/taggerless taggeremail:trim '' |
| 903 | test_atom refs/tags/taggerless taggeremail:localpart '' |
Mischa POSLAWSKY | 8b3f33e | 2019-08-17 23:51:07 +0200 | [diff] [blame] | 904 | test_atom refs/tags/taggerless taggerdate '' |
| 905 | test_atom refs/tags/taggerless committer '' |
| 906 | test_atom refs/tags/taggerless committername '' |
| 907 | test_atom refs/tags/taggerless committeremail '' |
Hariom Verma | b82445d | 2020-08-21 21:41:43 +0000 | [diff] [blame] | 908 | test_atom refs/tags/taggerless committeremail:trim '' |
| 909 | test_atom refs/tags/taggerless committeremail:localpart '' |
Mischa POSLAWSKY | 8b3f33e | 2019-08-17 23:51:07 +0200 | [diff] [blame] | 910 | test_atom refs/tags/taggerless committerdate '' |
| 911 | test_atom refs/tags/taggerless subject 'Broken tag' |
| 912 | |
Junio C Hamano | e276c26 | 2008-08-20 12:29:27 -0700 | [diff] [blame] | 913 | test_expect_success 'an unusual tag with an incomplete line' ' |
| 914 | |
| 915 | git tag -m "bogo" bogo && |
| 916 | bogo=$(git cat-file tag bogo) && |
| 917 | bogo=$(printf "%s" "$bogo" | git mktag) && |
| 918 | git tag -f bogo "$bogo" && |
| 919 | git for-each-ref --format "%(body)" refs/tags/bogo |
| 920 | |
| 921 | ' |
| 922 | |
Jeff King | 7140c22 | 2011-09-07 13:43:28 -0400 | [diff] [blame] | 923 | test_expect_success 'create tag with subject and body content' ' |
| 924 | cat >>msg <<-\EOF && |
| 925 | the subject line |
| 926 | |
| 927 | first body line |
| 928 | second body line |
| 929 | EOF |
| 930 | git tag -F msg subject-body |
| 931 | ' |
| 932 | test_atom refs/tags/subject-body subject 'the subject line' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 933 | test_atom refs/tags/subject-body subject:sanitize 'the-subject-line' |
Jeff King | 7140c22 | 2011-09-07 13:43:28 -0400 | [diff] [blame] | 934 | test_atom refs/tags/subject-body body 'first body line |
| 935 | second body line |
| 936 | ' |
| 937 | test_atom refs/tags/subject-body contents 'the subject line |
| 938 | |
| 939 | first body line |
| 940 | second body line |
| 941 | ' |
| 942 | |
Jeff King | 7f6e275 | 2011-09-07 13:44:56 -0400 | [diff] [blame] | 943 | test_expect_success 'create tag with multiline subject' ' |
| 944 | cat >msg <<-\EOF && |
| 945 | first subject line |
| 946 | second subject line |
| 947 | |
| 948 | first body line |
| 949 | second body line |
| 950 | EOF |
| 951 | git tag -F msg multiline |
| 952 | ' |
| 953 | test_atom refs/tags/multiline subject 'first subject line second subject line' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 954 | test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 955 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
Jeff King | 7f6e275 | 2011-09-07 13:44:56 -0400 | [diff] [blame] | 956 | test_atom refs/tags/multiline body 'first body line |
| 957 | second body line |
| 958 | ' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 959 | test_atom refs/tags/multiline contents:body 'first body line |
| 960 | second body line |
| 961 | ' |
| 962 | test_atom refs/tags/multiline contents:signature '' |
Jeff King | 7f6e275 | 2011-09-07 13:44:56 -0400 | [diff] [blame] | 963 | test_atom refs/tags/multiline contents 'first subject line |
| 964 | second subject line |
| 965 | |
| 966 | first body line |
| 967 | second body line |
| 968 | ' |
| 969 | |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 970 | test_expect_success GPG 'create signed tags' ' |
| 971 | git tag -s -m "" signed-empty && |
| 972 | git tag -s -m "subject line" signed-short && |
| 973 | cat >msg <<-\EOF && |
| 974 | subject line |
| 975 | |
| 976 | body contents |
| 977 | EOF |
| 978 | git tag -s -F msg signed-long |
| 979 | ' |
| 980 | |
| 981 | sig='-----BEGIN PGP SIGNATURE----- |
| 982 | -----END PGP SIGNATURE----- |
| 983 | ' |
| 984 | |
| 985 | PREREQ=GPG |
| 986 | test_atom refs/tags/signed-empty subject '' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 987 | test_atom refs/tags/signed-empty subject:sanitize '' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 988 | test_atom refs/tags/signed-empty contents:subject '' |
| 989 | test_atom refs/tags/signed-empty body "$sig" |
| 990 | test_atom refs/tags/signed-empty contents:body '' |
| 991 | test_atom refs/tags/signed-empty contents:signature "$sig" |
| 992 | test_atom refs/tags/signed-empty contents "$sig" |
| 993 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 994 | test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' ' |
| 995 | git cat-file tag refs/tags/signed-empty >expected && |
| 996 | git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual && |
| 997 | sanitize_pgp <expected >expected.clean && |
| 998 | echo >>expected.clean && |
| 999 | sanitize_pgp <actual >actual.clean && |
| 1000 | test_cmp expected.clean actual.clean |
| 1001 | ' |
| 1002 | |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 1003 | test_atom refs/tags/signed-short subject 'subject line' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 1004 | test_atom refs/tags/signed-short subject:sanitize 'subject-line' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 1005 | test_atom refs/tags/signed-short contents:subject 'subject line' |
| 1006 | test_atom refs/tags/signed-short body "$sig" |
| 1007 | test_atom refs/tags/signed-short contents:body '' |
| 1008 | test_atom refs/tags/signed-short contents:signature "$sig" |
| 1009 | test_atom refs/tags/signed-short contents "subject line |
| 1010 | $sig" |
| 1011 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1012 | test_expect_success GPG 'basic atom: refs/tags/signed-short raw' ' |
| 1013 | git cat-file tag refs/tags/signed-short >expected && |
| 1014 | git for-each-ref --format="%(raw)" refs/tags/signed-short >actual && |
| 1015 | sanitize_pgp <expected >expected.clean && |
| 1016 | echo >>expected.clean && |
| 1017 | sanitize_pgp <actual >actual.clean && |
| 1018 | test_cmp expected.clean actual.clean |
| 1019 | ' |
| 1020 | |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 1021 | test_atom refs/tags/signed-long subject 'subject line' |
Hariom Verma | 905f0a4 | 2020-08-21 21:41:50 +0000 | [diff] [blame] | 1022 | test_atom refs/tags/signed-long subject:sanitize 'subject-line' |
Michał Górny | e2b2397 | 2011-09-07 13:46:08 -0400 | [diff] [blame] | 1023 | test_atom refs/tags/signed-long contents:subject 'subject line' |
| 1024 | test_atom refs/tags/signed-long body "body contents |
| 1025 | $sig" |
| 1026 | test_atom refs/tags/signed-long contents:body 'body contents |
| 1027 | ' |
| 1028 | test_atom refs/tags/signed-long contents:signature "$sig" |
| 1029 | test_atom refs/tags/signed-long contents "subject line |
| 1030 | |
| 1031 | body contents |
| 1032 | $sig" |
| 1033 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1034 | test_expect_success GPG 'basic atom: refs/tags/signed-long raw' ' |
| 1035 | git cat-file tag refs/tags/signed-long >expected && |
| 1036 | git for-each-ref --format="%(raw)" refs/tags/signed-long >actual && |
| 1037 | sanitize_pgp <expected >expected.clean && |
| 1038 | echo >>expected.clean && |
| 1039 | sanitize_pgp <actual >actual.clean && |
| 1040 | test_cmp expected.clean actual.clean |
| 1041 | ' |
| 1042 | |
Christian Couder | 6e2ef8e | 2020-07-10 18:47:38 +0200 | [diff] [blame] | 1043 | test_expect_success 'set up refs pointing to tree and blob' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1044 | git update-ref refs/mytrees/first refs/heads/main^{tree} && |
| 1045 | git update-ref refs/myblobs/first refs/heads/main:one |
Christian Couder | 6e2ef8e | 2020-07-10 18:47:38 +0200 | [diff] [blame] | 1046 | ' |
| 1047 | |
| 1048 | test_atom refs/mytrees/first subject "" |
| 1049 | test_atom refs/mytrees/first contents:subject "" |
| 1050 | test_atom refs/mytrees/first body "" |
| 1051 | test_atom refs/mytrees/first contents:body "" |
| 1052 | test_atom refs/mytrees/first contents:signature "" |
| 1053 | test_atom refs/mytrees/first contents "" |
| 1054 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1055 | test_expect_success 'basic atom: refs/mytrees/first raw' ' |
| 1056 | git cat-file tree refs/mytrees/first >expected && |
| 1057 | echo >>expected && |
| 1058 | git for-each-ref --format="%(raw)" refs/mytrees/first >actual && |
| 1059 | test_cmp expected actual && |
| 1060 | git cat-file -s refs/mytrees/first >expected && |
| 1061 | git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual && |
| 1062 | test_cmp expected actual |
| 1063 | ' |
| 1064 | |
Christian Couder | 6e2ef8e | 2020-07-10 18:47:38 +0200 | [diff] [blame] | 1065 | test_atom refs/myblobs/first subject "" |
| 1066 | test_atom refs/myblobs/first contents:subject "" |
| 1067 | test_atom refs/myblobs/first body "" |
| 1068 | test_atom refs/myblobs/first contents:body "" |
| 1069 | test_atom refs/myblobs/first contents:signature "" |
| 1070 | test_atom refs/myblobs/first contents "" |
| 1071 | |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1072 | test_expect_success 'basic atom: refs/myblobs/first raw' ' |
| 1073 | git cat-file blob refs/myblobs/first >expected && |
| 1074 | echo >>expected && |
| 1075 | git for-each-ref --format="%(raw)" refs/myblobs/first >actual && |
| 1076 | test_cmp expected actual && |
| 1077 | git cat-file -s refs/myblobs/first >expected && |
| 1078 | git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual && |
| 1079 | test_cmp expected actual |
| 1080 | ' |
| 1081 | |
| 1082 | test_expect_success 'set up refs pointing to binary blob' ' |
| 1083 | printf "a\0b\0c" >blob1 && |
| 1084 | printf "a\0c\0b" >blob2 && |
| 1085 | printf "\0a\0b\0c" >blob3 && |
| 1086 | printf "abc" >blob4 && |
| 1087 | printf "\0 \0 \0 " >blob5 && |
| 1088 | printf "\0 \0a\0 " >blob6 && |
| 1089 | printf " " >blob7 && |
| 1090 | >blob8 && |
| 1091 | obj=$(git hash-object -w blob1) && |
| 1092 | git update-ref refs/myblobs/blob1 "$obj" && |
| 1093 | obj=$(git hash-object -w blob2) && |
| 1094 | git update-ref refs/myblobs/blob2 "$obj" && |
| 1095 | obj=$(git hash-object -w blob3) && |
| 1096 | git update-ref refs/myblobs/blob3 "$obj" && |
| 1097 | obj=$(git hash-object -w blob4) && |
| 1098 | git update-ref refs/myblobs/blob4 "$obj" && |
| 1099 | obj=$(git hash-object -w blob5) && |
| 1100 | git update-ref refs/myblobs/blob5 "$obj" && |
| 1101 | obj=$(git hash-object -w blob6) && |
| 1102 | git update-ref refs/myblobs/blob6 "$obj" && |
| 1103 | obj=$(git hash-object -w blob7) && |
| 1104 | git update-ref refs/myblobs/blob7 "$obj" && |
| 1105 | obj=$(git hash-object -w blob8) && |
| 1106 | git update-ref refs/myblobs/blob8 "$obj" |
| 1107 | ' |
| 1108 | |
| 1109 | test_expect_success 'Verify sorts with raw' ' |
| 1110 | cat >expected <<-EOF && |
| 1111 | refs/myblobs/blob8 |
| 1112 | refs/myblobs/blob5 |
| 1113 | refs/myblobs/blob6 |
| 1114 | refs/myblobs/blob3 |
| 1115 | refs/myblobs/blob7 |
| 1116 | refs/mytrees/first |
| 1117 | refs/myblobs/first |
| 1118 | refs/myblobs/blob1 |
| 1119 | refs/myblobs/blob2 |
| 1120 | refs/myblobs/blob4 |
| 1121 | refs/heads/main |
| 1122 | EOF |
| 1123 | git for-each-ref --format="%(refname)" --sort=raw \ |
| 1124 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && |
| 1125 | test_cmp expected actual |
| 1126 | ' |
| 1127 | |
| 1128 | test_expect_success 'Verify sorts with raw:size' ' |
| 1129 | cat >expected <<-EOF && |
| 1130 | refs/myblobs/blob8 |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1131 | refs/myblobs/blob7 |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1132 | refs/myblobs/blob4 |
| 1133 | refs/myblobs/blob1 |
| 1134 | refs/myblobs/blob2 |
| 1135 | refs/myblobs/blob3 |
| 1136 | refs/myblobs/blob5 |
| 1137 | refs/myblobs/blob6 |
Kousik Sanagavarapu | 6d79cd8 | 2023-09-02 14:30:39 +0530 | [diff] [blame] | 1138 | refs/myblobs/first |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1139 | refs/mytrees/first |
Kousik Sanagavarapu | 6d79cd8 | 2023-09-02 14:30:39 +0530 | [diff] [blame] | 1140 | refs/heads/main |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1141 | EOF |
| 1142 | git for-each-ref --format="%(refname)" --sort=raw:size \ |
| 1143 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && |
| 1144 | test_cmp expected actual |
| 1145 | ' |
| 1146 | |
| 1147 | test_expect_success 'validate raw atom with %(if:equals)' ' |
| 1148 | cat >expected <<-EOF && |
| 1149 | not equals |
| 1150 | not equals |
| 1151 | not equals |
| 1152 | not equals |
| 1153 | not equals |
| 1154 | not equals |
| 1155 | refs/myblobs/blob4 |
| 1156 | not equals |
| 1157 | not equals |
| 1158 | not equals |
| 1159 | not equals |
| 1160 | not equals |
| 1161 | EOF |
| 1162 | git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \ |
| 1163 | refs/myblobs/ refs/heads/ >actual && |
| 1164 | test_cmp expected actual |
| 1165 | ' |
| 1166 | |
| 1167 | test_expect_success 'validate raw atom with %(if:notequals)' ' |
| 1168 | cat >expected <<-EOF && |
| 1169 | refs/heads/ambiguous |
| 1170 | refs/heads/main |
| 1171 | refs/heads/newtag |
| 1172 | refs/myblobs/blob1 |
| 1173 | refs/myblobs/blob2 |
| 1174 | refs/myblobs/blob3 |
| 1175 | equals |
| 1176 | refs/myblobs/blob5 |
| 1177 | refs/myblobs/blob6 |
| 1178 | refs/myblobs/blob7 |
| 1179 | refs/myblobs/blob8 |
| 1180 | refs/myblobs/first |
| 1181 | EOF |
| 1182 | git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \ |
| 1183 | refs/myblobs/ refs/heads/ >actual && |
| 1184 | test_cmp expected actual |
| 1185 | ' |
| 1186 | |
| 1187 | test_expect_success 'empty raw refs with %(if)' ' |
| 1188 | cat >expected <<-EOF && |
| 1189 | refs/myblobs/blob1 not empty |
| 1190 | refs/myblobs/blob2 not empty |
| 1191 | refs/myblobs/blob3 not empty |
| 1192 | refs/myblobs/blob4 not empty |
| 1193 | refs/myblobs/blob5 not empty |
| 1194 | refs/myblobs/blob6 not empty |
| 1195 | refs/myblobs/blob7 empty |
| 1196 | refs/myblobs/blob8 empty |
| 1197 | refs/myblobs/first not empty |
| 1198 | EOF |
| 1199 | git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \ |
| 1200 | refs/myblobs/ >actual && |
| 1201 | test_cmp expected actual |
| 1202 | ' |
| 1203 | |
| 1204 | test_expect_success '%(raw) with --python must fail' ' |
| 1205 | test_must_fail git for-each-ref --format="%(raw)" --python |
| 1206 | ' |
| 1207 | |
| 1208 | test_expect_success '%(raw) with --tcl must fail' ' |
| 1209 | test_must_fail git for-each-ref --format="%(raw)" --tcl |
| 1210 | ' |
| 1211 | |
ZheNing Hu | 7121c4d | 2021-07-26 03:26:48 +0000 | [diff] [blame] | 1212 | test_expect_success '%(raw) with --perl' ' |
| 1213 | git for-each-ref --format="\$name= %(raw); |
| 1214 | print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual && |
| 1215 | cmp blob1 actual && |
| 1216 | git for-each-ref --format="\$name= %(raw); |
| 1217 | print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual && |
| 1218 | cmp blob3 actual && |
| 1219 | git for-each-ref --format="\$name= %(raw); |
| 1220 | print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual && |
| 1221 | cmp blob8 actual && |
| 1222 | git for-each-ref --format="\$name= %(raw); |
| 1223 | print \"\$name\"" refs/myblobs/first --perl | perl >actual && |
| 1224 | cmp one actual && |
| 1225 | git cat-file tree refs/mytrees/first > expected && |
| 1226 | git for-each-ref --format="\$name= %(raw); |
| 1227 | print \"\$name\"" refs/mytrees/first --perl | perl >actual && |
| 1228 | cmp expected actual |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1229 | ' |
| 1230 | |
| 1231 | test_expect_success '%(raw) with --shell must fail' ' |
| 1232 | test_must_fail git for-each-ref --format="%(raw)" --shell |
| 1233 | ' |
| 1234 | |
| 1235 | test_expect_success '%(raw) with --shell and --sort=raw must fail' ' |
| 1236 | test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell |
| 1237 | ' |
| 1238 | |
| 1239 | test_expect_success '%(raw:size) with --shell' ' |
Eric Sunshine | efe47c8 | 2021-12-09 00:11:02 -0500 | [diff] [blame] | 1240 | git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect && |
ZheNing Hu | bd0708c | 2021-07-26 03:26:47 +0000 | [diff] [blame] | 1241 | git for-each-ref --format="%(raw:size)" --shell >actual && |
| 1242 | test_cmp expect actual |
| 1243 | ' |
| 1244 | |
| 1245 | test_expect_success 'for-each-ref --format compare with cat-file --batch' ' |
| 1246 | git rev-parse refs/mytrees/first | git cat-file --batch >expected && |
| 1247 | git for-each-ref --format="%(objectname) %(objecttype) %(objectsize) |
| 1248 | %(raw)" refs/mytrees/first >actual && |
| 1249 | test_cmp expected actual |
| 1250 | ' |
| 1251 | |
Kousik Sanagavarapu | 6d79cd8 | 2023-09-02 14:30:39 +0530 | [diff] [blame] | 1252 | test_expect_success 'verify sorts with contents:size' ' |
| 1253 | cat >expect <<-\EOF && |
| 1254 | refs/heads/main |
| 1255 | refs/heads/newtag |
| 1256 | refs/heads/ambiguous |
| 1257 | EOF |
| 1258 | git for-each-ref --format="%(refname)" \ |
| 1259 | --sort=contents:size refs/heads/ >actual && |
| 1260 | test_cmp expect actual |
| 1261 | ' |
| 1262 | |
Jeff King | 7c5045f | 2020-05-03 05:13:09 -0400 | [diff] [blame] | 1263 | test_expect_success 'set up multiple-sort tags' ' |
| 1264 | for when in 100000 200000 |
| 1265 | do |
| 1266 | for email in user1 user2 |
| 1267 | do |
| 1268 | for ref in ref1 ref2 |
| 1269 | do |
| 1270 | GIT_COMMITTER_DATE="@$when +0000" \ |
| 1271 | GIT_COMMITTER_EMAIL="$email@example.com" \ |
| 1272 | git tag -m "tag $ref-$when-$email" \ |
| 1273 | multi-$ref-$when-$email || return 1 |
| 1274 | done |
| 1275 | done |
| 1276 | done |
| 1277 | ' |
Kacper Kornet | 912072d | 2012-08-21 09:46:06 +0200 | [diff] [blame] | 1278 | |
Kacper Kornet | 3b51222 | 2012-08-21 09:47:26 +0200 | [diff] [blame] | 1279 | test_expect_success 'Verify sort with multiple keys' ' |
Jeff King | 7c5045f | 2020-05-03 05:13:09 -0400 | [diff] [blame] | 1280 | cat >expected <<-\EOF && |
| 1281 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 |
| 1282 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 |
| 1283 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 |
| 1284 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 |
| 1285 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 |
| 1286 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 |
| 1287 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 |
| 1288 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 |
| 1289 | EOF |
| 1290 | git for-each-ref \ |
| 1291 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ |
| 1292 | --sort=-refname \ |
| 1293 | --sort=taggeremail \ |
| 1294 | --sort=taggerdate \ |
| 1295 | "refs/tags/multi-*" >actual && |
Kacper Kornet | 912072d | 2012-08-21 09:46:06 +0200 | [diff] [blame] | 1296 | test_cmp expected actual |
| 1297 | ' |
Junio C Hamano | 84679d4 | 2016-11-18 15:21:12 -0800 | [diff] [blame] | 1298 | |
Jeff King | 7c5045f | 2020-05-03 05:13:09 -0400 | [diff] [blame] | 1299 | test_expect_success 'equivalent sorts fall back on refname' ' |
| 1300 | cat >expected <<-\EOF && |
| 1301 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 |
| 1302 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 |
| 1303 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 |
| 1304 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 |
| 1305 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 |
| 1306 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 |
| 1307 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 |
| 1308 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 |
| 1309 | EOF |
| 1310 | git for-each-ref \ |
| 1311 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ |
| 1312 | --sort=taggerdate \ |
| 1313 | "refs/tags/multi-*" >actual && |
| 1314 | test_cmp expected actual |
| 1315 | ' |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 1316 | |
Junio C Hamano | 98e7ab6 | 2021-10-20 12:23:53 -0700 | [diff] [blame] | 1317 | test_expect_success '--no-sort cancels the previous sort keys' ' |
| 1318 | cat >expected <<-\EOF && |
| 1319 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 |
| 1320 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 |
| 1321 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 |
| 1322 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 |
| 1323 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 |
| 1324 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 |
| 1325 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 |
| 1326 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 |
| 1327 | EOF |
| 1328 | git for-each-ref \ |
| 1329 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ |
| 1330 | --sort=-refname \ |
| 1331 | --sort=taggeremail \ |
| 1332 | --no-sort \ |
| 1333 | --sort=taggerdate \ |
| 1334 | "refs/tags/multi-*" >actual && |
| 1335 | test_cmp expected actual |
| 1336 | ' |
| 1337 | |
Victoria Dye | 56d26ad | 2023-11-14 19:53:49 +0000 | [diff] [blame] | 1338 | test_expect_success '--no-sort without subsequent --sort prints expected refs' ' |
| 1339 | cat >expected <<-\EOF && |
| 1340 | refs/tags/multi-ref1-100000-user1 |
| 1341 | refs/tags/multi-ref1-100000-user2 |
| 1342 | refs/tags/multi-ref1-200000-user1 |
| 1343 | refs/tags/multi-ref1-200000-user2 |
| 1344 | refs/tags/multi-ref2-100000-user1 |
| 1345 | refs/tags/multi-ref2-100000-user2 |
| 1346 | refs/tags/multi-ref2-200000-user1 |
| 1347 | refs/tags/multi-ref2-200000-user2 |
| 1348 | EOF |
| 1349 | |
| 1350 | # Sort the results with `sort` for a consistent comparison against |
| 1351 | # expected |
| 1352 | git for-each-ref \ |
| 1353 | --format="%(refname)" \ |
| 1354 | --no-sort \ |
| 1355 | "refs/tags/multi-*" | sort >actual && |
| 1356 | test_cmp expected actual |
| 1357 | ' |
| 1358 | |
Victoria Dye | 46176d7 | 2024-02-08 01:57:19 +0000 | [diff] [blame] | 1359 | test_expect_success 'set up custom date sorting' ' |
| 1360 | # Dates: |
| 1361 | # - Wed Feb 07 2024 21:34:20 +0000 |
| 1362 | # - Tue Dec 14 1999 00:05:22 +0000 |
| 1363 | # - Fri Jun 04 2021 11:26:51 +0000 |
| 1364 | # - Mon Jan 22 2007 16:44:01 GMT+0000 |
| 1365 | i=1 && |
| 1366 | for when in 1707341660 945129922 1622806011 1169484241 |
| 1367 | do |
| 1368 | GIT_COMMITTER_DATE="@$when +0000" \ |
| 1369 | GIT_COMMITTER_EMAIL="user@example.com" \ |
| 1370 | git tag -m "tag $when" custom-dates-$i && |
| 1371 | i=$(($i+1)) || return 1 |
| 1372 | done |
| 1373 | ' |
| 1374 | |
| 1375 | test_expect_success 'sort by date defaults to full timestamp' ' |
| 1376 | cat >expected <<-\EOF && |
| 1377 | 945129922 refs/tags/custom-dates-2 |
| 1378 | 1169484241 refs/tags/custom-dates-4 |
| 1379 | 1622806011 refs/tags/custom-dates-3 |
| 1380 | 1707341660 refs/tags/custom-dates-1 |
| 1381 | EOF |
| 1382 | |
| 1383 | git for-each-ref \ |
| 1384 | --format="%(creatordate:unix) %(refname)" \ |
| 1385 | --sort=creatordate \ |
| 1386 | "refs/tags/custom-dates-*" >actual && |
| 1387 | test_cmp expected actual |
| 1388 | ' |
| 1389 | |
| 1390 | test_expect_success 'sort by custom date format' ' |
| 1391 | cat >expected <<-\EOF && |
| 1392 | 00:05:22 refs/tags/custom-dates-2 |
| 1393 | 11:26:51 refs/tags/custom-dates-3 |
| 1394 | 16:44:01 refs/tags/custom-dates-4 |
| 1395 | 21:34:20 refs/tags/custom-dates-1 |
| 1396 | EOF |
| 1397 | |
| 1398 | git for-each-ref \ |
| 1399 | --format="%(creatordate:format:%H:%M:%S) %(refname)" \ |
| 1400 | --sort="creatordate:format:%H:%M:%S" \ |
| 1401 | "refs/tags/custom-dates-*" >actual && |
| 1402 | test_cmp expected actual |
| 1403 | ' |
| 1404 | |
Junio C Hamano | 84679d4 | 2016-11-18 15:21:12 -0800 | [diff] [blame] | 1405 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1406 | test_when_finished "git checkout main" && |
Junio C Hamano | 84679d4 | 2016-11-18 15:21:12 -0800 | [diff] [blame] | 1407 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
| 1408 | sed -e "s/^\* / /" actual >expect && |
Jeff King | f0252ca | 2017-02-27 04:29:31 -0500 | [diff] [blame] | 1409 | git checkout --orphan orphaned-branch && |
Junio C Hamano | 84679d4 | 2016-11-18 15:21:12 -0800 | [diff] [blame] | 1410 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
| 1411 | test_cmp expect actual |
| 1412 | ' |
| 1413 | |
Jacob Keller | b1d31c8 | 2016-11-18 16:58:15 -0800 | [diff] [blame] | 1414 | cat >trailers <<EOF |
| 1415 | Reviewed-by: A U Thor <author@example.com> |
| 1416 | Signed-off-by: A U Thor <author@example.com> |
Taylor Blau | 624b44d | 2017-10-01 22:25:22 -0700 | [diff] [blame] | 1417 | [ v2 updated patch description ] |
| 1418 | Acked-by: A U Thor |
| 1419 | <author@example.com> |
Jacob Keller | b1d31c8 | 2016-11-18 16:58:15 -0800 | [diff] [blame] | 1420 | EOF |
| 1421 | |
Taylor Blau | 67a20a0 | 2017-10-01 22:25:23 -0700 | [diff] [blame] | 1422 | unfold () { |
| 1423 | perl -0pe 's/\n\s+/ /g' |
| 1424 | } |
Taylor Blau | 624b44d | 2017-10-01 22:25:22 -0700 | [diff] [blame] | 1425 | |
| 1426 | test_expect_success 'set up trailers for next test' ' |
Jacob Keller | b1d31c8 | 2016-11-18 16:58:15 -0800 | [diff] [blame] | 1427 | echo "Some contents" > two && |
| 1428 | git add two && |
Taylor Blau | 624b44d | 2017-10-01 22:25:22 -0700 | [diff] [blame] | 1429 | git commit -F - <<-EOF |
Jacob Keller | b1d31c8 | 2016-11-18 16:58:15 -0800 | [diff] [blame] | 1430 | trailers: this commit message has trailers |
| 1431 | |
| 1432 | Some message contents |
| 1433 | |
| 1434 | $(cat trailers) |
| 1435 | EOF |
Taylor Blau | 624b44d | 2017-10-01 22:25:22 -0700 | [diff] [blame] | 1436 | ' |
| 1437 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1438 | test_trailer_option () { |
| 1439 | title=$1 option=$2 |
| 1440 | cat >expect |
| 1441 | test_expect_success "$title" ' |
| 1442 | git for-each-ref --format="%($option)" refs/heads/main >actual && |
| 1443 | test_cmp expect actual && |
| 1444 | git for-each-ref --format="%(contents:$option)" refs/heads/main >actual && |
| 1445 | test_cmp expect actual |
| 1446 | ' |
| 1447 | } |
Taylor Blau | 67a20a0 | 2017-10-01 22:25:23 -0700 | [diff] [blame] | 1448 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1449 | test_trailer_option '%(trailers:unfold) unfolds trailers' \ |
| 1450 | 'trailers:unfold' <<-EOF |
| 1451 | $(unfold <trailers) |
Taylor Blau | 67a20a0 | 2017-10-01 22:25:23 -0700 | [diff] [blame] | 1452 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1453 | EOF |
Taylor Blau | 7a5edbd | 2017-10-01 22:25:24 -0700 | [diff] [blame] | 1454 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1455 | test_trailer_option '%(trailers:only) shows only "key: value" trailers' \ |
| 1456 | 'trailers:only' <<-EOF |
| 1457 | $(grep -v patch.description <trailers) |
| 1458 | |
| 1459 | EOF |
| 1460 | |
Hariom Verma | ee82a48 | 2021-02-13 01:52:43 +0000 | [diff] [blame] | 1461 | test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \ |
| 1462 | 'trailers:only=no,only=true' <<-EOF |
| 1463 | $(grep -v patch.description <trailers) |
| 1464 | |
| 1465 | EOF |
| 1466 | |
| 1467 | test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \ |
| 1468 | 'trailers:only=yes' <<-EOF |
| 1469 | $(grep -v patch.description <trailers) |
| 1470 | |
| 1471 | EOF |
| 1472 | |
| 1473 | test_trailer_option '%(trailers:only=no) shows all trailers' \ |
| 1474 | 'trailers:only=no' <<-EOF |
| 1475 | $(cat trailers) |
| 1476 | |
| 1477 | EOF |
| 1478 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1479 | test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \ |
| 1480 | 'trailers:only,unfold' <<-EOF |
| 1481 | $(grep -v patch.description <trailers | unfold) |
| 1482 | |
| 1483 | EOF |
| 1484 | |
| 1485 | test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \ |
| 1486 | 'trailers:unfold,only' <<-EOF |
| 1487 | $(grep -v patch.description <trailers | unfold) |
| 1488 | |
| 1489 | EOF |
| 1490 | |
Hariom Verma | ee82a48 | 2021-02-13 01:52:43 +0000 | [diff] [blame] | 1491 | test_trailer_option '%(trailers:key=foo) shows that trailer' \ |
| 1492 | 'trailers:key=Signed-off-by' <<-EOF |
| 1493 | Signed-off-by: A U Thor <author@example.com> |
| 1494 | |
| 1495 | EOF |
| 1496 | |
| 1497 | test_trailer_option '%(trailers:key=foo) is case insensitive' \ |
| 1498 | 'trailers:key=SiGned-oFf-bY' <<-EOF |
| 1499 | Signed-off-by: A U Thor <author@example.com> |
| 1500 | |
| 1501 | EOF |
| 1502 | |
| 1503 | test_trailer_option '%(trailers:key=foo:) trailing colon also works' \ |
| 1504 | 'trailers:key=Signed-off-by:' <<-EOF |
| 1505 | Signed-off-by: A U Thor <author@example.com> |
| 1506 | |
| 1507 | EOF |
| 1508 | |
| 1509 | test_trailer_option '%(trailers:key=foo) multiple keys' \ |
| 1510 | 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF |
| 1511 | Reviewed-by: A U Thor <author@example.com> |
| 1512 | Signed-off-by: A U Thor <author@example.com> |
| 1513 | |
| 1514 | EOF |
| 1515 | |
| 1516 | test_trailer_option '%(trailers:key=nonexistent) becomes empty' \ |
| 1517 | 'trailers:key=Shined-off-by:' <<-EOF |
| 1518 | |
| 1519 | EOF |
| 1520 | |
| 1521 | test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \ |
| 1522 | 'trailers:key=Acked-by' <<-EOF |
| 1523 | $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by) |
| 1524 | |
| 1525 | EOF |
| 1526 | |
| 1527 | test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \ |
| 1528 | 'trailers:key=Signed-Off-by,unfold' <<-EOF |
| 1529 | $(unfold <trailers | grep Signed-off-by) |
| 1530 | |
| 1531 | EOF |
| 1532 | |
| 1533 | test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \ |
| 1534 | 'trailers:key=Signed-off-by,only=no' <<-EOF |
| 1535 | Signed-off-by: A U Thor <author@example.com> |
| 1536 | $(grep patch.description <trailers) |
| 1537 | |
| 1538 | EOF |
| 1539 | |
| 1540 | test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \ |
| 1541 | 'trailers:key=Signed-off-by,valueonly' <<-EOF |
| 1542 | A U Thor <author@example.com> |
| 1543 | |
| 1544 | EOF |
| 1545 | |
| 1546 | test_trailer_option '%(trailers:separator) changes separator' \ |
| 1547 | 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF |
| 1548 | Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com> |
| 1549 | EOF |
| 1550 | |
| 1551 | test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \ |
| 1552 | 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF |
| 1553 | Reviewed-by,A U Thor <author@example.com> |
| 1554 | Signed-off-by,A U Thor <author@example.com> |
| 1555 | |
| 1556 | EOF |
| 1557 | |
| 1558 | test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \ |
| 1559 | 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF |
| 1560 | Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com> |
| 1561 | EOF |
| 1562 | |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1563 | test_failing_trailer_option () { |
| 1564 | title=$1 option=$2 |
| 1565 | cat >expect |
| 1566 | test_expect_success "$title" ' |
| 1567 | # error message cannot be checked under i18n |
| 1568 | test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual && |
Ævar Arnfjörð Bjarmason | feeb03b | 2021-04-13 14:19:51 +0200 | [diff] [blame] | 1569 | test_cmp expect actual && |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1570 | test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual && |
Ævar Arnfjörð Bjarmason | feeb03b | 2021-04-13 14:19:51 +0200 | [diff] [blame] | 1571 | test_cmp expect actual |
Hariom Verma | 727331d | 2021-02-13 01:52:40 +0000 | [diff] [blame] | 1572 | ' |
| 1573 | } |
| 1574 | |
| 1575 | test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \ |
| 1576 | 'trailers:unsupported' <<-\EOF |
Taylor Blau | 67a20a0 | 2017-10-01 22:25:23 -0700 | [diff] [blame] | 1577 | fatal: unknown %(trailers) argument: unsupported |
| 1578 | EOF |
Taylor Blau | 67a20a0 | 2017-10-01 22:25:23 -0700 | [diff] [blame] | 1579 | |
Hariom Verma | ee82a48 | 2021-02-13 01:52:43 +0000 | [diff] [blame] | 1580 | test_failing_trailer_option '%(trailers:key) without value is error' \ |
| 1581 | 'trailers:key' <<-\EOF |
| 1582 | fatal: expected %(trailers:key=<value>) |
| 1583 | EOF |
| 1584 | |
Hariom Verma | 2c22e10 | 2020-08-21 21:06:14 +0000 | [diff] [blame] | 1585 | test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' ' |
Taylor Blau | 7a5edbd | 2017-10-01 22:25:24 -0700 | [diff] [blame] | 1586 | cat >expect <<-EOF && |
Hariom Verma | 2c22e10 | 2020-08-21 21:06:14 +0000 | [diff] [blame] | 1587 | fatal: unrecognized %(contents) argument: trailersonly |
Taylor Blau | 7a5edbd | 2017-10-01 22:25:24 -0700 | [diff] [blame] | 1588 | EOF |
Hariom Verma | 2c22e10 | 2020-08-21 21:06:14 +0000 | [diff] [blame] | 1589 | test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual && |
Ævar Arnfjörð Bjarmason | feeb03b | 2021-04-13 14:19:51 +0200 | [diff] [blame] | 1590 | test_cmp expect actual |
Taylor Blau | 7a5edbd | 2017-10-01 22:25:24 -0700 | [diff] [blame] | 1591 | ' |
| 1592 | |
Taylor Blau | 624b44d | 2017-10-01 22:25:22 -0700 | [diff] [blame] | 1593 | test_expect_success 'basic atom: head contents:trailers' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1594 | git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual && |
Jacob Keller | b1d31c8 | 2016-11-18 16:58:15 -0800 | [diff] [blame] | 1595 | sanitize_pgp <actual >actual.clean && |
| 1596 | # git for-each-ref ends with a blank line |
| 1597 | cat >expect <<-EOF && |
| 1598 | $(cat trailers) |
| 1599 | |
| 1600 | EOF |
| 1601 | test_cmp expect actual.clean |
| 1602 | ' |
| 1603 | |
ZheNing Hu | b9dee07 | 2021-07-26 03:26:50 +0000 | [diff] [blame] | 1604 | test_expect_success 'basic atom: rest must fail' ' |
| 1605 | test_must_fail git for-each-ref --format="%(rest)" refs/heads/main |
| 1606 | ' |
| 1607 | |
Jeff King | a33d0fa | 2022-12-14 11:19:43 -0500 | [diff] [blame] | 1608 | test_expect_success 'HEAD atom does not take arguments' ' |
| 1609 | test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err && |
| 1610 | echo "fatal: %(HEAD) does not take arguments" >expect && |
| 1611 | test_cmp expect err |
| 1612 | ' |
| 1613 | |
Jeff King | dda4fc1 | 2022-12-14 11:20:19 -0500 | [diff] [blame] | 1614 | test_expect_success 'subject atom rejects unknown arguments' ' |
| 1615 | test_must_fail git for-each-ref --format="%(subject:foo)" 2>err && |
| 1616 | echo "fatal: unrecognized %(subject) argument: foo" >expect && |
| 1617 | test_cmp expect err |
| 1618 | ' |
| 1619 | |
Jeff King | 1955ef1 | 2022-12-14 11:23:53 -0500 | [diff] [blame] | 1620 | test_expect_success 'refname atom rejects unknown arguments' ' |
| 1621 | test_must_fail git for-each-ref --format="%(refname:foo)" 2>err && |
| 1622 | echo "fatal: unrecognized %(refname) argument: foo" >expect && |
| 1623 | test_cmp expect err |
| 1624 | ' |
| 1625 | |
Jeff King | e5fba5d | 2018-08-22 20:50:17 -0400 | [diff] [blame] | 1626 | test_expect_success 'trailer parsing not fooled by --- line' ' |
| 1627 | git commit --allow-empty -F - <<-\EOF && |
| 1628 | this is the subject |
| 1629 | |
| 1630 | This is the body. The message has a "---" line which would confuse a |
| 1631 | message+patch parser. But here we know we have only a commit message, |
| 1632 | so we get it right. |
| 1633 | |
| 1634 | trailer: wrong |
| 1635 | --- |
| 1636 | This is more body. |
| 1637 | |
| 1638 | trailer: right |
| 1639 | EOF |
| 1640 | |
| 1641 | { |
| 1642 | echo "trailer: right" && |
| 1643 | echo |
| 1644 | } >expect && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1645 | git for-each-ref --format="%(trailers)" refs/heads/main >actual && |
Jeff King | e5fba5d | 2018-08-22 20:50:17 -0400 | [diff] [blame] | 1646 | test_cmp expect actual |
| 1647 | ' |
| 1648 | |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 1649 | test_expect_success 'Add symbolic ref for the following tests' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1650 | git symbolic-ref refs/heads/sym refs/heads/main |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 1651 | ' |
| 1652 | |
| 1653 | cat >expected <<EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1654 | refs/heads/main |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 1655 | EOF |
| 1656 | |
| 1657 | test_expect_success 'Verify usage of %(symref) atom' ' |
| 1658 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && |
| 1659 | test_cmp expected actual |
| 1660 | ' |
| 1661 | |
| 1662 | cat >expected <<EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1663 | heads/main |
Karthik Nayak | 01f9582 | 2017-01-10 14:19:42 +0530 | [diff] [blame] | 1664 | EOF |
| 1665 | |
| 1666 | test_expect_success 'Verify usage of %(symref:short) atom' ' |
| 1667 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && |
| 1668 | test_cmp expected actual |
| 1669 | ' |
| 1670 | |
Karthik Nayak | a798410 | 2017-01-10 14:19:44 +0530 | [diff] [blame] | 1671 | cat >expected <<EOF |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1672 | main |
| 1673 | heads/main |
Karthik Nayak | a798410 | 2017-01-10 14:19:44 +0530 | [diff] [blame] | 1674 | EOF |
| 1675 | |
Karthik Nayak | 17938f1 | 2017-01-10 14:19:46 +0530 | [diff] [blame] | 1676 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
| 1677 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && |
Karthik Nayak | 1a0ca5e | 2017-01-10 14:19:48 +0530 | [diff] [blame] | 1678 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
Junio C Hamano | 44a6b6c | 2017-02-07 11:50:34 -0800 | [diff] [blame] | 1679 | test_cmp expected actual && |
| 1680 | |
| 1681 | git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual && |
| 1682 | git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual && |
Karthik Nayak | a798410 | 2017-01-10 14:19:44 +0530 | [diff] [blame] | 1683 | test_cmp expected actual |
| 1684 | ' |
| 1685 | |
Karthik Nayak | 1a34728 | 2017-01-10 14:19:49 +0530 | [diff] [blame] | 1686 | cat >expected <<EOF |
| 1687 | refs |
| 1688 | refs/heads |
| 1689 | EOF |
| 1690 | |
| 1691 | test_expect_success 'Verify usage of %(symref:rstrip) atom' ' |
| 1692 | git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual && |
| 1693 | git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual && |
| 1694 | test_cmp expected actual |
| 1695 | ' |
| 1696 | |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1697 | test_expect_success ':remotename and :remoteref' ' |
| 1698 | git init remote-tests && |
| 1699 | ( |
| 1700 | cd remote-tests && |
| 1701 | test_commit initial && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1702 | git branch -M main && |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1703 | git remote add from fifth.coffee:blub && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1704 | git config branch.main.remote from && |
| 1705 | git config branch.main.merge refs/heads/stable && |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1706 | git remote add to southridge.audio:repo && |
| 1707 | git config remote.to.push "refs/heads/*:refs/heads/pushed/*" && |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1708 | git config branch.main.pushRemote to && |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1709 | for pair in "%(upstream)=refs/remotes/from/stable" \ |
| 1710 | "%(upstream:remotename)=from" \ |
| 1711 | "%(upstream:remoteref)=refs/heads/stable" \ |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1712 | "%(push)=refs/remotes/to/pushed/main" \ |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1713 | "%(push:remotename)=to" \ |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1714 | "%(push:remoteref)=refs/heads/pushed/main" |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1715 | do |
| 1716 | echo "${pair#*=}" >expect && |
| 1717 | git for-each-ref --format="${pair%=*}" \ |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1718 | refs/heads/main >actual && |
Eric Sunshine | 0c51d6b | 2021-12-09 00:11:15 -0500 | [diff] [blame] | 1719 | test_cmp expect actual || exit 1 |
Johannes Schindelin | 1b58686 | 2017-11-07 17:31:14 +0100 | [diff] [blame] | 1720 | done && |
| 1721 | git branch push-simple && |
| 1722 | git config branch.push-simple.pushRemote from && |
| 1723 | actual="$(git for-each-ref \ |
| 1724 | --format="%(push:remotename),%(push:remoteref)" \ |
| 1725 | refs/heads/push-simple)" && |
| 1726 | test from, = "$actual" |
| 1727 | ) |
| 1728 | ' |
| 1729 | |
Jeff King | e674eb2 | 2018-07-02 17:12:42 -0400 | [diff] [blame] | 1730 | test_expect_success 'for-each-ref --ignore-case ignores case' ' |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1731 | git for-each-ref --format="%(refname)" refs/heads/MAIN >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 1732 | test_must_be_empty actual && |
Jeff King | ee0f3e2 | 2018-07-02 17:11:23 -0400 | [diff] [blame] | 1733 | |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1734 | echo refs/heads/main >expect && |
Jeff King | ee0f3e2 | 2018-07-02 17:11:23 -0400 | [diff] [blame] | 1735 | git for-each-ref --format="%(refname)" --ignore-case \ |
Johannes Schindelin | 8f19c9f | 2020-12-06 13:15:59 +0000 | [diff] [blame] | 1736 | refs/heads/MAIN >actual && |
Jeff King | ee0f3e2 | 2018-07-02 17:11:23 -0400 | [diff] [blame] | 1737 | test_cmp expect actual |
| 1738 | ' |
| 1739 | |
Øystein Walle | aabfdc9 | 2023-04-07 19:53:16 +0200 | [diff] [blame] | 1740 | test_expect_success 'for-each-ref --omit-empty works' ' |
| 1741 | git for-each-ref --format="%(refname)" >actual && |
| 1742 | test_line_count -gt 1 actual && |
| 1743 | git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual && |
| 1744 | echo refs/heads/main >expect && |
| 1745 | test_cmp expect actual |
| 1746 | ' |
| 1747 | |
Jeff King | 76f9e56 | 2020-05-03 05:11:57 -0400 | [diff] [blame] | 1748 | test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' |
| 1749 | # name refs numerically to avoid case-insensitive filesystem conflicts |
| 1750 | nr=0 && |
| 1751 | for email in a A b B |
| 1752 | do |
| 1753 | for subject in a A b B |
| 1754 | do |
| 1755 | GIT_COMMITTER_EMAIL="$email@example.com" \ |
| 1756 | git tag -m "tag $subject" icase-$(printf %02d $nr) && |
| 1757 | nr=$((nr+1))|| |
| 1758 | return 1 |
| 1759 | done |
| 1760 | done && |
| 1761 | git for-each-ref --ignore-case \ |
| 1762 | --format="%(taggeremail) %(subject) %(refname)" \ |
| 1763 | --sort=refname \ |
| 1764 | --sort=subject \ |
| 1765 | --sort=taggeremail \ |
| 1766 | refs/tags/icase-* >actual && |
| 1767 | cat >expect <<-\EOF && |
| 1768 | <a@example.com> tag a refs/tags/icase-00 |
| 1769 | <a@example.com> tag A refs/tags/icase-01 |
| 1770 | <A@example.com> tag a refs/tags/icase-04 |
| 1771 | <A@example.com> tag A refs/tags/icase-05 |
| 1772 | <a@example.com> tag b refs/tags/icase-02 |
| 1773 | <a@example.com> tag B refs/tags/icase-03 |
| 1774 | <A@example.com> tag b refs/tags/icase-06 |
| 1775 | <A@example.com> tag B refs/tags/icase-07 |
| 1776 | <b@example.com> tag a refs/tags/icase-08 |
| 1777 | <b@example.com> tag A refs/tags/icase-09 |
| 1778 | <B@example.com> tag a refs/tags/icase-12 |
| 1779 | <B@example.com> tag A refs/tags/icase-13 |
| 1780 | <b@example.com> tag b refs/tags/icase-10 |
| 1781 | <b@example.com> tag B refs/tags/icase-11 |
| 1782 | <B@example.com> tag b refs/tags/icase-14 |
| 1783 | <B@example.com> tag B refs/tags/icase-15 |
| 1784 | EOF |
| 1785 | test_cmp expect actual |
| 1786 | ' |
| 1787 | |
Jeff King | c685450 | 2021-04-01 04:32:24 -0400 | [diff] [blame] | 1788 | test_expect_success 'for-each-ref reports broken tags' ' |
| 1789 | git tag -m "good tag" broken-tag-good HEAD && |
| 1790 | git cat-file tag broken-tag-good >good && |
| 1791 | sed s/commit/blob/ <good >bad && |
| 1792 | bad=$(git hash-object -w -t tag bad) && |
| 1793 | git update-ref refs/tags/broken-tag-bad $bad && |
| 1794 | test_must_fail git for-each-ref --format="%(*objectname)" \ |
| 1795 | refs/tags/broken-tag-* |
| 1796 | ' |
| 1797 | |
Jeff King | b01e1c7 | 2022-11-02 03:42:07 -0400 | [diff] [blame] | 1798 | test_expect_success 'set up tag with signature and no blank lines' ' |
| 1799 | git tag -F - fake-sig-no-blanks <<-\EOF |
| 1800 | this is the subject |
| 1801 | -----BEGIN PGP SIGNATURE----- |
| 1802 | not a real signature, but we just care about the |
| 1803 | subject/body parsing. It is important here that |
| 1804 | there are no blank lines in the signature. |
| 1805 | -----END PGP SIGNATURE----- |
| 1806 | EOF |
| 1807 | ' |
| 1808 | |
| 1809 | test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject' |
| 1810 | test_atom refs/tags/fake-sig-no-blanks contents:body '' |
| 1811 | test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig" |
| 1812 | |
Jeff King | 8e1c5fc | 2022-11-02 03:44:00 -0400 | [diff] [blame] | 1813 | test_expect_success 'set up tag with CRLF signature' ' |
| 1814 | append_cr <<-\EOF | |
| 1815 | this is the subject |
| 1816 | -----BEGIN PGP SIGNATURE----- |
| 1817 | |
| 1818 | not a real signature, but we just care about |
| 1819 | the subject/body parsing. It is important here |
| 1820 | that there is a blank line separating this |
| 1821 | from the signature header. |
| 1822 | -----END PGP SIGNATURE----- |
| 1823 | EOF |
| 1824 | git tag -F - --cleanup=verbatim fake-sig-crlf |
| 1825 | ' |
| 1826 | |
| 1827 | test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject' |
| 1828 | test_atom refs/tags/fake-sig-crlf contents:body '' |
| 1829 | |
| 1830 | # CRLF is retained in the signature, so we have to pass our expected value |
| 1831 | # through append_cr. But test_atom requires a shell string, which means command |
| 1832 | # substitution, and the shell will strip trailing newlines from the output of |
| 1833 | # the substitution. Hack around it by adding and then removing a dummy line. |
| 1834 | sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)" |
| 1835 | sig_crlf=${sig_crlf%dummy} |
| 1836 | test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf" |
| 1837 | |
Derrick Stolee | b73dec5 | 2023-03-20 11:26:47 +0000 | [diff] [blame] | 1838 | test_expect_success 'git for-each-ref --stdin: empty' ' |
| 1839 | >in && |
| 1840 | git for-each-ref --format="%(refname)" --stdin <in >actual && |
| 1841 | git for-each-ref --format="%(refname)" >expect && |
| 1842 | test_cmp expect actual |
| 1843 | ' |
| 1844 | |
| 1845 | test_expect_success 'git for-each-ref --stdin: fails if extra args' ' |
| 1846 | >in && |
| 1847 | test_must_fail git for-each-ref --format="%(refname)" \ |
| 1848 | --stdin refs/heads/extra <in 2>err && |
| 1849 | grep "unknown arguments supplied with --stdin" err |
| 1850 | ' |
| 1851 | |
| 1852 | test_expect_success 'git for-each-ref --stdin: matches' ' |
| 1853 | cat >in <<-EOF && |
| 1854 | refs/tags/multi* |
| 1855 | refs/heads/amb* |
| 1856 | EOF |
| 1857 | |
| 1858 | cat >expect <<-EOF && |
| 1859 | refs/heads/ambiguous |
| 1860 | refs/tags/multi-ref1-100000-user1 |
| 1861 | refs/tags/multi-ref1-100000-user2 |
| 1862 | refs/tags/multi-ref1-200000-user1 |
| 1863 | refs/tags/multi-ref1-200000-user2 |
| 1864 | refs/tags/multi-ref2-100000-user1 |
| 1865 | refs/tags/multi-ref2-100000-user2 |
| 1866 | refs/tags/multi-ref2-200000-user1 |
| 1867 | refs/tags/multi-ref2-200000-user2 |
| 1868 | refs/tags/multiline |
| 1869 | EOF |
| 1870 | |
| 1871 | git for-each-ref --format="%(refname)" --stdin <in >actual && |
| 1872 | test_cmp expect actual |
| 1873 | ' |
| 1874 | |
Derrick Stolee | b2c51b7 | 2023-03-20 11:26:48 +0000 | [diff] [blame] | 1875 | test_expect_success 'git for-each-ref with non-existing refs' ' |
| 1876 | cat >in <<-EOF && |
| 1877 | refs/heads/this-ref-does-not-exist |
| 1878 | refs/tags/bogus |
| 1879 | EOF |
| 1880 | |
| 1881 | git for-each-ref --format="%(refname)" --stdin <in >actual && |
| 1882 | test_must_be_empty actual && |
| 1883 | |
| 1884 | xargs git for-each-ref --format="%(refname)" <in >actual && |
| 1885 | test_must_be_empty actual |
| 1886 | ' |
| 1887 | |
Victoria Dye | 188782e | 2023-11-14 19:53:57 +0000 | [diff] [blame] | 1888 | test_expect_success 'git for-each-ref with nested tags' ' |
| 1889 | git tag -am "Normal tag" nested/base HEAD && |
| 1890 | git tag -am "Nested tag" nested/nest1 refs/tags/nested/base && |
| 1891 | git tag -am "Double nested tag" nested/nest2 refs/tags/nested/nest1 && |
| 1892 | |
| 1893 | head_oid="$(git rev-parse HEAD)" && |
| 1894 | base_tag_oid="$(git rev-parse refs/tags/nested/base)" && |
| 1895 | nest1_tag_oid="$(git rev-parse refs/tags/nested/nest1)" && |
| 1896 | nest2_tag_oid="$(git rev-parse refs/tags/nested/nest2)" && |
| 1897 | |
| 1898 | cat >expect <<-EOF && |
| 1899 | refs/tags/nested/base $base_tag_oid tag $head_oid commit |
| 1900 | refs/tags/nested/nest1 $nest1_tag_oid tag $head_oid commit |
| 1901 | refs/tags/nested/nest2 $nest2_tag_oid tag $head_oid commit |
| 1902 | EOF |
| 1903 | |
| 1904 | git for-each-ref \ |
| 1905 | --format="%(refname) %(objectname) %(objecttype) %(*objectname) %(*objecttype)" \ |
| 1906 | refs/tags/nested/ >actual && |
| 1907 | test_cmp expect actual |
| 1908 | ' |
| 1909 | |
Kousik Sanagavarapu | 26c9c03 | 2023-06-04 23:52:47 +0530 | [diff] [blame] | 1910 | GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)" |
| 1911 | TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)" |
| 1912 | |
| 1913 | test_expect_success GPG 'setup for signature atom using gpg' ' |
| 1914 | git checkout -b signed && |
| 1915 | |
| 1916 | test_when_finished "test_unconfig commit.gpgSign" && |
| 1917 | |
| 1918 | echo "1" >file && |
| 1919 | git add file && |
| 1920 | test_tick && |
| 1921 | git commit -S -m "file: 1" && |
| 1922 | git tag first-signed && |
| 1923 | |
| 1924 | echo "2" >file && |
| 1925 | test_tick && |
| 1926 | git commit -a -m "file: 2" && |
| 1927 | git tag second-unsigned && |
| 1928 | |
| 1929 | git config commit.gpgSign 1 && |
| 1930 | echo "3" >file && |
| 1931 | test_tick && |
| 1932 | git commit -a --no-gpg-sign -m "file: 3" && |
| 1933 | git tag third-unsigned && |
| 1934 | |
| 1935 | test_tick && |
| 1936 | git rebase -f HEAD^^ && git tag second-signed HEAD^ && |
| 1937 | git tag third-signed && |
| 1938 | |
| 1939 | echo "4" >file && |
| 1940 | test_tick && |
| 1941 | git commit -a -SB7227189 -m "file: 4" && |
| 1942 | git tag fourth-signed && |
| 1943 | |
| 1944 | echo "5" >file && |
| 1945 | test_tick && |
| 1946 | git commit -a --no-gpg-sign -m "file: 5" && |
| 1947 | git tag fifth-unsigned && |
| 1948 | |
| 1949 | echo "6" >file && |
| 1950 | test_tick && |
| 1951 | git commit -a --no-gpg-sign -m "file: 6" && |
| 1952 | |
| 1953 | test_tick && |
| 1954 | git rebase -f HEAD^^ && |
| 1955 | git tag fifth-signed HEAD^ && |
| 1956 | git tag sixth-signed && |
| 1957 | |
| 1958 | echo "7" >file && |
| 1959 | test_tick && |
| 1960 | git commit -a --no-gpg-sign -m "file: 7" && |
| 1961 | git tag seventh-unsigned |
| 1962 | ' |
| 1963 | |
| 1964 | test_expect_success GPGSSH 'setup for signature atom using ssh' ' |
| 1965 | test_when_finished "test_unconfig gpg.format user.signingkey" && |
| 1966 | |
| 1967 | test_config gpg.format ssh && |
| 1968 | test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" && |
| 1969 | echo "8" >file && |
| 1970 | test_tick && |
René Scharfe | 065135f | 2023-07-16 10:17:35 +0200 | [diff] [blame] | 1971 | git add file && |
| 1972 | git commit -S -m "file: 8" && |
Kousik Sanagavarapu | 26c9c03 | 2023-06-04 23:52:47 +0530 | [diff] [blame] | 1973 | git tag eighth-signed-ssh |
| 1974 | ' |
| 1975 | |
| 1976 | test_expect_success GPG2 'bare signature atom' ' |
Christian Hesse | d0fc552 | 2023-08-22 15:03:15 +0200 | [diff] [blame] | 1977 | git verify-commit first-signed 2>expect && |
Kousik Sanagavarapu | 26c9c03 | 2023-06-04 23:52:47 +0530 | [diff] [blame] | 1978 | echo >>expect && |
| 1979 | git for-each-ref refs/tags/first-signed \ |
| 1980 | --format="%(signature)" >actual && |
| 1981 | test_cmp expect actual |
| 1982 | ' |
| 1983 | |
| 1984 | test_expect_success GPG 'show good signature with custom format' ' |
| 1985 | git verify-commit first-signed && |
| 1986 | cat >expect <<-\EOF && |
| 1987 | G |
| 1988 | 13B6F51ECDDE430D |
| 1989 | C O Mitter <committer@example.com> |
| 1990 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
| 1991 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
| 1992 | EOF |
| 1993 | git for-each-ref refs/tags/first-signed \ |
| 1994 | --format="$GRADE_FORMAT" >actual && |
| 1995 | test_cmp expect actual |
| 1996 | ' |
| 1997 | test_expect_success GPGSSH 'show good signature with custom format |
| 1998 | with ssh' ' |
| 1999 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 2000 | FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") && |
| 2001 | cat >expect.tmpl <<-\EOF && |
| 2002 | G |
| 2003 | FINGERPRINT |
| 2004 | principal with number 1 |
| 2005 | FINGERPRINT |
| 2006 | |
| 2007 | EOF |
| 2008 | sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect && |
| 2009 | git for-each-ref refs/tags/eighth-signed-ssh \ |
| 2010 | --format="$GRADE_FORMAT" >actual && |
| 2011 | test_cmp expect actual |
| 2012 | ' |
| 2013 | |
| 2014 | test_expect_success GPG 'signature atom with grade option and bad signature' ' |
| 2015 | git cat-file commit third-signed >raw && |
| 2016 | sed -e "s/^file: 3/file: 3 forged/" raw >forged1 && |
| 2017 | FORGED1=$(git hash-object -w -t commit forged1) && |
| 2018 | git update-ref refs/tags/third-signed "$FORGED1" && |
| 2019 | test_must_fail git verify-commit "$FORGED1" && |
| 2020 | |
| 2021 | cat >expect <<-\EOF && |
| 2022 | B |
| 2023 | 13B6F51ECDDE430D |
| 2024 | C O Mitter <committer@example.com> |
| 2025 | |
| 2026 | |
| 2027 | EOF |
| 2028 | git for-each-ref refs/tags/third-signed \ |
| 2029 | --format="$GRADE_FORMAT" >actual && |
| 2030 | test_cmp expect actual |
| 2031 | ' |
| 2032 | |
| 2033 | test_expect_success GPG 'show untrusted signature with custom format' ' |
| 2034 | cat >expect <<-\EOF && |
| 2035 | U |
| 2036 | 65A0EEA02E30CAD7 |
| 2037 | Eris Discordia <discord@example.net> |
| 2038 | F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 |
| 2039 | D4BE22311AD3131E5EDA29A461092E85B7227189 |
| 2040 | EOF |
| 2041 | git for-each-ref refs/tags/fourth-signed \ |
| 2042 | --format="$GRADE_FORMAT" >actual && |
| 2043 | test_cmp expect actual |
| 2044 | ' |
| 2045 | |
| 2046 | test_expect_success GPG 'show untrusted signature with undefined trust level' ' |
| 2047 | cat >expect <<-\EOF && |
| 2048 | undefined |
| 2049 | 65A0EEA02E30CAD7 |
| 2050 | Eris Discordia <discord@example.net> |
| 2051 | F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 |
| 2052 | D4BE22311AD3131E5EDA29A461092E85B7227189 |
| 2053 | EOF |
| 2054 | git for-each-ref refs/tags/fourth-signed \ |
| 2055 | --format="$TRUSTLEVEL_FORMAT" >actual && |
| 2056 | test_cmp expect actual |
| 2057 | ' |
| 2058 | |
| 2059 | test_expect_success GPG 'show untrusted signature with ultimate trust level' ' |
| 2060 | cat >expect <<-\EOF && |
| 2061 | ultimate |
| 2062 | 13B6F51ECDDE430D |
| 2063 | C O Mitter <committer@example.com> |
| 2064 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
| 2065 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
| 2066 | EOF |
| 2067 | git for-each-ref refs/tags/sixth-signed \ |
| 2068 | --format="$TRUSTLEVEL_FORMAT" >actual && |
| 2069 | test_cmp expect actual |
| 2070 | ' |
| 2071 | |
| 2072 | test_expect_success GPG 'show unknown signature with custom format' ' |
| 2073 | cat >expect <<-\EOF && |
| 2074 | E |
| 2075 | 13B6F51ECDDE430D |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | EOF |
| 2080 | GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \ |
| 2081 | refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual && |
| 2082 | test_cmp expect actual |
| 2083 | ' |
| 2084 | |
| 2085 | test_expect_success GPG 'show lack of signature with custom format' ' |
| 2086 | cat >expect <<-\EOF && |
| 2087 | N |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | EOF |
| 2093 | git for-each-ref refs/tags/seventh-unsigned \ |
| 2094 | --format="$GRADE_FORMAT" >actual && |
| 2095 | test_cmp expect actual |
| 2096 | ' |
| 2097 | |
Andy Parkins | 96b2d4f | 2007-10-02 12:02:57 +0100 | [diff] [blame] | 2098 | test_done |