Git fork
1#!/bin/sh
2
3test_description='test finding specific blobs in the revision walking'
4
5. ./test-lib.sh
6
7test_expect_success 'setup ' '
8 git commit --allow-empty -m "empty initial commit" &&
9
10 echo "Hello, world!" >greeting &&
11 git add greeting &&
12 git commit -m "add the greeting blob" && # borrowed from Git from the Bottom Up
13 git tag -m "the blob" greeting $(git rev-parse HEAD:greeting) &&
14
15 echo asdf >unrelated &&
16 git add unrelated &&
17 git commit -m "unrelated history" &&
18
19 git revert HEAD^ &&
20
21 git commit --allow-empty -m "another unrelated commit"
22'
23
24test_expect_success 'find the greeting blob' '
25 cat >expect <<-EOF &&
26 Revert "add the greeting blob"
27 add the greeting blob
28 EOF
29
30 git log --format=%s --find-object=greeting^{blob} >actual &&
31
32 test_cmp expect actual
33'
34
35test_expect_success 'setup a tree' '
36 mkdir a &&
37 echo asdf >a/file &&
38 git add a/file &&
39 git commit -m "add a file in a subdirectory"
40'
41
42test_expect_success 'find a tree' '
43 cat >expect <<-EOF &&
44 add a file in a subdirectory
45 EOF
46
47 git log --format=%s -t --find-object=HEAD:a >actual &&
48
49 test_cmp expect actual
50'
51
52test_expect_success 'setup a submodule' '
53 test_create_repo sub &&
54 test_commit -C sub sub &&
55 git submodule add ./sub sub &&
56 git commit -a -m "add sub"
57'
58
59test_expect_success 'find a submodule' '
60 cat >expect <<-EOF &&
61 add sub
62 EOF
63
64 git log --format=%s --find-object=HEAD:sub >actual &&
65
66 test_cmp expect actual
67'
68
69test_expect_success 'set up merge tests' '
70 test_commit base &&
71
72 git checkout -b boring base^ &&
73 echo boring >file &&
74 git add file &&
75 git commit -m boring &&
76
77 git checkout -b interesting base^ &&
78 echo interesting >file &&
79 git add file &&
80 git commit -m interesting &&
81
82 blob=$(git rev-parse interesting:file)
83'
84
85test_expect_success 'detect merge which introduces blob' '
86 git checkout -B merge base &&
87 git merge --no-commit boring &&
88 echo interesting >file &&
89 git commit -am "introduce blob" &&
90 git diff-tree --format=%s --find-object=$blob -c --name-status HEAD >actual &&
91 cat >expect <<-\EOF &&
92 introduce blob
93
94 AM file
95 EOF
96 test_cmp expect actual
97'
98
99test_expect_success 'detect merge which removes blob' '
100 git checkout -B merge interesting &&
101 git merge --no-commit base &&
102 echo boring >file &&
103 git commit -am "remove blob" &&
104 git diff-tree --format=%s --find-object=$blob -c --name-status HEAD >actual &&
105 cat >expect <<-\EOF &&
106 remove blob
107
108 MA file
109 EOF
110 test_cmp expect actual
111'
112
113test_expect_success 'do not detect merge that does not touch blob' '
114 git checkout -B merge interesting &&
115 git merge -m "untouched blob" base &&
116 git diff-tree --format=%s --find-object=$blob -c --name-status HEAD >actual &&
117 cat >expect <<-\EOF &&
118 untouched blob
119
120 EOF
121 test_cmp expect actual
122'
123
124test_done