Change unpack_trees' 'reset' flag into an enum
[alt-git.git] / t / t0002-gitfile.sh
blob8440e6add1237e7d08f6b0010950b0d96b9e920d
1 #!/bin/sh
3 test_description='.git file
5 Verify that plumbing commands work when .git is a file
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 . ./test-lib.sh
12 objpath() {
13 echo "$1" | sed -e 's|\(..\)|\1/|'
16 test_expect_success 'initial setup' '
17 REAL="$(pwd)/.real" &&
18 mv .git "$REAL"
21 test_expect_success 'bad setup: invalid .git file format' '
22 echo "gitdir $REAL" >.git &&
23 test_must_fail git rev-parse 2>.err &&
24 test_i18ngrep "invalid gitfile format" .err
27 test_expect_success 'bad setup: invalid .git file path' '
28 echo "gitdir: $REAL.not" >.git &&
29 test_must_fail git rev-parse 2>.err &&
30 test_i18ngrep "not a git repository" .err
33 test_expect_success 'final setup + check rev-parse --git-dir' '
34 echo "gitdir: $REAL" >.git &&
35 test "$REAL" = "$(git rev-parse --git-dir)"
38 test_expect_success 'check hash-object' '
39 echo "foo" >bar &&
40 SHA=$(cat bar | git hash-object -w --stdin) &&
41 test_path_is_file "$REAL/objects/$(objpath $SHA)"
44 test_expect_success 'check cat-file' '
45 git cat-file blob $SHA >actual &&
46 test_cmp bar actual
49 test_expect_success 'check update-index' '
50 test_path_is_missing "$REAL/index" &&
51 rm -f "$REAL/objects/$(objpath $SHA)" &&
52 git update-index --add bar &&
53 test_path_is_file "$REAL/index" &&
54 test_path_is_file "$REAL/objects/$(objpath $SHA)"
57 test_expect_success 'check write-tree' '
58 SHA=$(git write-tree) &&
59 test_path_is_file "$REAL/objects/$(objpath $SHA)"
62 test_expect_success 'check commit-tree' '
63 SHA=$(echo "commit bar" | git commit-tree $SHA) &&
64 test_path_is_file "$REAL/objects/$(objpath $SHA)"
67 test_expect_success 'check rev-list' '
68 git update-ref "HEAD" "$SHA" &&
69 test "$SHA" = "$(git rev-list HEAD)"
72 test_expect_success 'setup_git_dir twice in subdir' '
73 git init sgd &&
75 cd sgd &&
76 git config alias.lsfi ls-files &&
77 mv .git .realgit &&
78 echo "gitdir: .realgit" >.git &&
79 mkdir subdir &&
80 cd subdir &&
81 >foo &&
82 git add foo &&
83 git lsfi >actual &&
84 echo foo >expected &&
85 test_cmp expected actual
89 test_expect_success 'enter_repo non-strict mode' '
90 test_create_repo enter_repo &&
92 cd enter_repo &&
93 test_tick &&
94 test_commit foo &&
95 mv .git .realgit &&
96 echo "gitdir: .realgit" >.git
97 ) &&
98 head=$(git -C enter_repo rev-parse HEAD) &&
99 git ls-remote enter_repo >actual &&
100 cat >expected <<-EOF &&
101 $head HEAD
102 $head refs/heads/main
103 $head refs/tags/foo
105 test_cmp expected actual
108 test_expect_success 'enter_repo linked checkout' '
110 cd enter_repo &&
111 git worktree add ../foo refs/tags/foo
112 ) &&
113 head=$(git -C enter_repo rev-parse HEAD) &&
114 git ls-remote foo >actual &&
115 cat >expected <<-EOF &&
116 $head HEAD
117 $head refs/heads/main
118 $head refs/tags/foo
120 test_cmp expected actual
123 test_expect_success 'enter_repo strict mode' '
124 head=$(git -C enter_repo rev-parse HEAD) &&
125 git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
126 cat >expected <<-EOF &&
127 $head HEAD
128 $head refs/heads/main
129 $head refs/tags/foo
131 test_cmp expected actual
134 test_done