]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0001-init.sh
Documentation/git-checkout: Update summary to reflect current abilities
[thirdparty/git.git] / t / t0001-init.sh
CommitLineData
6adcca3f
JH
1#!/bin/sh
2
3test_description='git init'
4
5. ./test-lib.sh
6
7check_config () {
8 if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
9 then
10 : happy
11 else
12 echo "expected a directory $1, a file $1/config and $1/refs"
13 return 1
14 fi
15 bare=$(GIT_CONFIG="$1/config" git config --bool core.bare)
16 worktree=$(GIT_CONFIG="$1/config" git config core.worktree) ||
17 worktree=unset
18
19 test "$bare" = "$2" && test "$worktree" = "$3" || {
20 echo "expected bare=$2 worktree=$3"
21 echo " got bare=$bare worktree=$worktree"
22 return 1
23 }
24}
25
26test_expect_success 'plain' '
27 (
51884080 28 unset GIT_DIR GIT_WORK_TREE
6adcca3f
JH
29 mkdir plain &&
30 cd plain &&
31 git init
32 ) &&
33 check_config plain/.git false unset
34'
35
36test_expect_success 'plain with GIT_WORK_TREE' '
37 if (
51884080 38 unset GIT_DIR
6adcca3f
JH
39 mkdir plain-wt &&
40 cd plain-wt &&
41 GIT_WORK_TREE=$(pwd) git init
42 )
43 then
44 echo Should have failed -- GIT_WORK_TREE should not be used
45 false
46 fi
47'
48
49test_expect_success 'plain bare' '
50 (
51884080 51 unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
6adcca3f
JH
52 mkdir plain-bare-1 &&
53 cd plain-bare-1 &&
54 git --bare init
55 ) &&
56 check_config plain-bare-1 true unset
57'
58
59test_expect_success 'plain bare with GIT_WORK_TREE' '
60 if (
51884080 61 unset GIT_DIR GIT_CONFIG
6adcca3f
JH
62 mkdir plain-bare-2 &&
63 cd plain-bare-2 &&
64 GIT_WORK_TREE=$(pwd) git --bare init
65 )
66 then
67 echo Should have failed -- GIT_WORK_TREE should not be used
68 false
69 fi
70'
71
72test_expect_success 'GIT_DIR bare' '
73
74 (
51884080 75 unset GIT_CONFIG
6adcca3f
JH
76 mkdir git-dir-bare.git &&
77 GIT_DIR=git-dir-bare.git git init
78 ) &&
79 check_config git-dir-bare.git true unset
80'
81
82test_expect_success 'GIT_DIR non-bare' '
83
84 (
51884080 85 unset GIT_CONFIG
6adcca3f
JH
86 mkdir non-bare &&
87 cd non-bare &&
88 GIT_DIR=.git git init
89 ) &&
90 check_config non-bare/.git false unset
91'
92
93test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
94
95 (
51884080 96 unset GIT_CONFIG
6adcca3f
JH
97 mkdir git-dir-wt-1.git &&
98 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
99 ) &&
100 check_config git-dir-wt-1.git false "$(pwd)"
101'
102
103test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
104
105 if (
51884080 106 unset GIT_CONFIG
6adcca3f
JH
107 mkdir git-dir-wt-2.git &&
108 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
109 )
110 then
111 echo Should have failed -- --bare should not be used
112 false
113 fi
114'
115
116test_done