Skip to content

Commit 28014c1

Browse files
committed
Merge branch 'bc/hash-independent-tests-part-6'
Test updates to prepare for SHA-2 transition continues. * bc/hash-independent-tests-part-6: t4048: abstract away SHA-1-specific constants t4045: make hash-size independent t4044: update test to work with SHA-256 t4039: abstract away SHA-1-specific constants t4038: abstract away SHA-1 specific constants t4034: abstract away SHA-1-specific constants t4027: make hash-size independent t4015: abstract away SHA-1-specific constants t4011: abstract away SHA-1-specific constants t4010: abstract away SHA-1-specific constants t3429: remove SHA1 annotation t1305: avoid comparing extensions rev-parse: add a --show-object-format option t/oid-info: add empty tree and empty blob values t/oid-info: allow looking up hash algorithm name
2 parents 57b5301 + fa26d5e commit 28014c1

16 files changed

+277
-155
lines changed

Documentation/git-rev-parse.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ print a message to stderr and exit with nonzero status.
274274
Show the path to the shared index file in split index mode, or
275275
empty if not in split-index mode.
276276

277+
--show-object-format[=(storage|input|output)]::
278+
Show the object format (hash algorithm) used for the repository
279+
for storage inside the `.git` directory, input, or output. For
280+
input, multiple algorithms may be printed, space-separated.
281+
If not specified, the default is "storage".
282+
283+
277284
Other Options
278285
~~~~~~~~~~~~~
279286

builtin/rev-parse.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
919919
show_datestring("--min-age=", arg);
920920
continue;
921921
}
922+
if (opt_with_value(arg, "--show-object-format", &arg)) {
923+
const char *val = arg ? arg : "storage";
924+
925+
if (strcmp(val, "storage") &&
926+
strcmp(val, "input") &&
927+
strcmp(val, "output"))
928+
die("unknown mode for --show-object-format: %s",
929+
arg);
930+
puts(the_hash_algo->name);
931+
continue;
932+
}
922933
if (show_flag(arg) && verify)
923934
die_no_single_rev(quiet);
924935
continue;

t/oid-info/hash-info

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ hexsz sha256:64
66

77
zero sha1:0000000000000000000000000000000000000000
88
zero sha256:0000000000000000000000000000000000000000000000000000000000000000
9+
10+
algo sha1:sha1
11+
algo sha256:sha256
12+
13+
empty_blob sha1:e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
14+
empty_blob sha256:473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813
15+
16+
empty_tree sha1:4b825dc642cb6eb9a060e54bf8d69288fbee4904
17+
empty_tree sha256:6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321

t/t1305-config-include.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success 'listing includes option and expansion' '
6363
test.one=1
6464
EOF
6565
git config --list >actual.full &&
66-
grep -v ^core actual.full >actual &&
66+
grep -v -e ^core -e ^extensions actual.full >actual &&
6767
test_cmp expect actual
6868
'
6969

t/t1500-rev-parse.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ test_rev_parse () {
5959
ROOT=$(pwd)
6060

6161
test_expect_success 'setup' '
62+
test_oid_init &&
6263
mkdir -p sub/dir work &&
6364
cp -R .git repo.git
6465
'
@@ -131,6 +132,20 @@ test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
131132
test_cmp expect actual
132133
'
133134

135+
test_expect_success 'rev-parse --show-object-format in repo' '
136+
echo "$(test_oid algo)" >expect &&
137+
git rev-parse --show-object-format >actual &&
138+
test_cmp expect actual &&
139+
git rev-parse --show-object-format=storage >actual &&
140+
test_cmp expect actual &&
141+
git rev-parse --show-object-format=input >actual &&
142+
test_cmp expect actual &&
143+
git rev-parse --show-object-format=output >actual &&
144+
test_cmp expect actual &&
145+
test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
146+
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
147+
'
148+
134149
test_expect_success 'showing the superproject correctly' '
135150
git rev-parse --show-superproject-working-tree >out &&
136151
test_must_be_empty out &&

t/t3429-rebase-edit-todo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success 'rebase exec modifies rebase-todo' '
1717
test -e F
1818
'
1919

20-
test_expect_success SHA1 'loose object cache vs re-reading todo list' '
20+
test_expect_success 'loose object cache vs re-reading todo list' '
2121
GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
2222
export GIT_REBASE_TODO &&
2323
write_script append-todo.sh <<-\EOS &&

t/t4010-diff-pathspec.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ test_expect_success \
1717
'echo frotz >file0 &&
1818
mkdir path1 &&
1919
echo rezrov >path1/file1 &&
20+
before0=$(git hash-object file0) &&
21+
before1=$(git hash-object path1/file1) &&
2022
git update-index --add file0 path1/file1 &&
2123
tree=$(git write-tree) &&
2224
echo "$tree" &&
2325
echo nitfol >file0 &&
2426
echo yomin >path1/file1 &&
27+
after0=$(git hash-object file0) &&
28+
after1=$(git hash-object path1/file1) &&
2529
git update-index file0 path1/file1'
2630

2731
cat >expected <<\EOF
@@ -31,32 +35,32 @@ test_expect_success \
3135
'git diff-index --cached $tree -- path >current &&
3236
compare_diff_raw current expected'
3337

34-
cat >expected <<\EOF
35-
:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
38+
cat >expected <<EOF
39+
:100644 100644 $before1 $after1 M path1/file1
3640
EOF
3741
test_expect_success \
3842
'limit to path1 should show path1/file1' \
3943
'git diff-index --cached $tree -- path1 >current &&
4044
compare_diff_raw current expected'
4145

42-
cat >expected <<\EOF
43-
:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
46+
cat >expected <<EOF
47+
:100644 100644 $before1 $after1 M path1/file1
4448
EOF
4549
test_expect_success \
4650
'limit to path1/ should show path1/file1' \
4751
'git diff-index --cached $tree -- path1/ >current &&
4852
compare_diff_raw current expected'
4953

50-
cat >expected <<\EOF
51-
:100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
54+
cat >expected <<EOF
55+
:100644 100644 $before1 $after1 M path1/file1
5256
EOF
5357
test_expect_success \
5458
'"*file1" should show path1/file1' \
5559
'git diff-index --cached $tree -- "*file1" >current &&
5660
compare_diff_raw current expected'
5761

58-
cat >expected <<\EOF
59-
:100644 100644 8e4020bb5a8d8c873b25de15933e75cc0fc275df dca6b92303befc93086aa025d90a5facd7eb2812 M file0
62+
cat >expected <<EOF
63+
:100644 100644 $before0 $after0 M file0
6064
EOF
6165
test_expect_success \
6266
'limit to file0 should show file0' \

t/t4011-diff-symlink.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,32 @@ test_description='Test diff of symlinks.
99
. ./test-lib.sh
1010
. "$TEST_DIRECTORY"/diff-lib.sh
1111

12+
# Print the short OID of a symlink with the given name.
13+
symlink_oid () {
14+
local oid=$(printf "%s" "$1" | git hash-object --stdin) &&
15+
git rev-parse --short "$oid"
16+
}
17+
18+
# Print the short OID of the given file.
19+
short_oid () {
20+
local oid=$(git hash-object "$1") &&
21+
git rev-parse --short "$oid"
22+
}
23+
1224
test_expect_success 'diff new symlink and file' '
13-
cat >expected <<-\EOF &&
25+
symlink=$(symlink_oid xyzzy) &&
26+
cat >expected <<-EOF &&
1427
diff --git a/frotz b/frotz
1528
new file mode 120000
16-
index 0000000..7c465af
29+
index 0000000..$symlink
1730
--- /dev/null
1831
+++ b/frotz
1932
@@ -0,0 +1 @@
2033
+xyzzy
2134
\ No newline at end of file
2235
diff --git a/nitfol b/nitfol
2336
new file mode 100644
24-
index 0000000..7c465af
37+
index 0000000..$symlink
2538
--- /dev/null
2639
+++ b/nitfol
2740
@@ -0,0 +1 @@
@@ -46,18 +59,18 @@ test_expect_success 'diff unchanged symlink and file' '
4659
'
4760

4861
test_expect_success 'diff removed symlink and file' '
49-
cat >expected <<-\EOF &&
62+
cat >expected <<-EOF &&
5063
diff --git a/frotz b/frotz
5164
deleted file mode 120000
52-
index 7c465af..0000000
65+
index $symlink..0000000
5366
--- a/frotz
5467
+++ /dev/null
5568
@@ -1 +0,0 @@
5669
-xyzzy
5770
\ No newline at end of file
5871
diff --git a/nitfol b/nitfol
5972
deleted file mode 100644
60-
index 7c465af..0000000
73+
index $symlink..0000000
6174
--- a/nitfol
6275
+++ /dev/null
6376
@@ -1 +0,0 @@
@@ -90,9 +103,10 @@ test_expect_success 'diff identical, but newly created symlink and file' '
90103
'
91104

92105
test_expect_success 'diff different symlink and file' '
93-
cat >expected <<-\EOF &&
106+
new=$(symlink_oid yxyyz) &&
107+
cat >expected <<-EOF &&
94108
diff --git a/frotz b/frotz
95-
index 7c465af..df1db54 120000
109+
index $symlink..$new 120000
96110
--- a/frotz
97111
+++ b/frotz
98112
@@ -1 +1 @@
@@ -101,7 +115,7 @@ test_expect_success 'diff different symlink and file' '
101115
+yxyyz
102116
\ No newline at end of file
103117
diff --git a/nitfol b/nitfol
104-
index 7c465af..df1db54 100644
118+
index $symlink..$new 100644
105119
--- a/nitfol
106120
+++ b/nitfol
107121
@@ -1 +1 @@
@@ -137,14 +151,16 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
137151
'
138152

139153
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
140-
cat >expect <<-\EOF &&
154+
file=$(short_oid file.bin) &&
155+
link=$(symlink_oid file.bin) &&
156+
cat >expect <<-EOF &&
141157
diff --git a/file.bin b/file.bin
142158
new file mode 100644
143-
index 0000000..d95f3ad
159+
index 0000000..$file
144160
Binary files /dev/null and b/file.bin differ
145161
diff --git a/link.bin b/link.bin
146162
new file mode 120000
147-
index 0000000..dce41ec
163+
index 0000000..$link
148164
--- /dev/null
149165
+++ b/link.bin
150166
@@ -0,0 +1 @@

0 commit comments

Comments
 (0)