blob: 44bd9ef45fd6d320e50f00fb0f86505fac2d7955 [file] [log] [blame]
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -05001#!/bin/sh
2
Nanako Shiraishi3604e7c2008-09-03 17:59:29 +09003test_description='git pack-object --include-tag'
Johannes Schindelin966b4be2020-11-18 23:44:29 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -05007. ./test-lib.sh
8
Elia Pinto0469cb92015-12-23 14:45:51 +01009TRASH=$(pwd)
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050010
11test_expect_success setup '
12 echo c >d &&
13 git update-index --add d &&
Elia Pinto0469cb92015-12-23 14:45:51 +010014 tree=$(git write-tree) &&
15 commit=$(git commit-tree $tree </dev/null) &&
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050016 echo "object $commit" >sig &&
17 echo "type commit" >>sig &&
18 echo "tag mytag" >>sig &&
19 echo "tagger $(git var GIT_COMMITTER_IDENT)" >>sig &&
20 echo >>sig &&
21 echo "our test tag" >>sig &&
Elia Pinto0469cb92015-12-23 14:45:51 +010022 tag=$(git mktag <sig) &&
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050023 rm d sig &&
24 git update-ref refs/tags/mytag $tag && {
25 echo $tree &&
26 echo $commit &&
27 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
28 } >obj-list
29'
30
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050031test_expect_success 'pack without --include-tag' '
Jeff Kingab517832016-09-05 17:52:22 -040032 packname=$(git pack-objects \
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050033 --window=0 \
Jeff Kingab517832016-09-05 17:52:22 -040034 test-no-include <obj-list)
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050035'
36
37test_expect_success 'unpack objects' '
Jeff King1962d9f2016-09-05 17:52:10 -040038 rm -rf clone.git &&
Jeff King948a7fd2016-09-05 17:52:17 -040039 git init clone.git &&
Jeff Kingab517832016-09-05 17:52:22 -040040 git -C clone.git unpack-objects <test-no-include-${packname}.pack
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050041'
42
43test_expect_success 'check unpacked result (have commit, no tag)' '
44 git rev-list --objects $commit >list.expect &&
Jeff King948a7fd2016-09-05 17:52:17 -040045 test_must_fail git -C clone.git cat-file -e $tag &&
46 git -C clone.git rev-list --objects $commit >list.actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070047 test_cmp list.expect list.actual
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050048'
49
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050050test_expect_success 'pack with --include-tag' '
Jeff Kingab517832016-09-05 17:52:22 -040051 packname=$(git pack-objects \
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050052 --window=0 \
53 --include-tag \
Jeff Kingab517832016-09-05 17:52:22 -040054 test-include <obj-list)
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050055'
56
57test_expect_success 'unpack objects' '
Jeff King1962d9f2016-09-05 17:52:10 -040058 rm -rf clone.git &&
Jeff King948a7fd2016-09-05 17:52:17 -040059 git init clone.git &&
Jeff Kingab517832016-09-05 17:52:22 -040060 git -C clone.git unpack-objects <test-include-${packname}.pack
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050061'
62
63test_expect_success 'check unpacked result (have commit, have tag)' '
64 git rev-list --objects mytag >list.expect &&
Jeff King948a7fd2016-09-05 17:52:17 -040065 git -C clone.git rev-list --objects $tag >list.actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -070066 test_cmp list.expect list.actual
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -050067'
68
Jeff Kingb773dde2016-09-05 17:52:26 -040069# A tag of a tag, where the "inner" tag is not otherwise
70# reachable, and a full peel points to a commit reachable from HEAD.
71test_expect_success 'create hidden inner tag' '
72 test_commit commit &&
73 git tag -m inner inner HEAD &&
74 git tag -m outer outer inner &&
75 git tag -d inner
76'
77
78test_expect_success 'pack explicit outer tag' '
79 packname=$(
80 {
81 echo HEAD &&
82 echo outer
83 } |
84 git pack-objects --revs test-hidden-explicit
85 )
86'
87
88test_expect_success 'unpack objects' '
89 rm -rf clone.git &&
90 git init clone.git &&
91 git -C clone.git unpack-objects <test-hidden-explicit-${packname}.pack
92'
93
94test_expect_success 'check unpacked result (have all objects)' '
95 git -C clone.git rev-list --objects $(git rev-parse outer HEAD)
96'
97
98test_expect_success 'pack implied outer tag' '
99 packname=$(
100 echo HEAD |
101 git pack-objects --revs --include-tag test-hidden-implied
102 )
103'
104
105test_expect_success 'unpack objects' '
106 rm -rf clone.git &&
107 git init clone.git &&
108 git -C clone.git unpack-objects <test-hidden-implied-${packname}.pack
109'
110
111test_expect_success 'check unpacked result (have all objects)' '
112 git -C clone.git rev-list --objects $(git rev-parse outer HEAD)
113'
114
115test_expect_success 'single-branch clone can transfer tag' '
116 rm -rf clone.git &&
Johannes Schindelin966b4be2020-11-18 23:44:29 +0000117 git clone --no-local --single-branch -b main . clone.git &&
Jeff Kingb773dde2016-09-05 17:52:26 -0400118 git -C clone.git fsck
119'
120
Shawn O. Pearcef0a24aa2008-03-03 22:27:20 -0500121test_done