Skip to content

Commit 4ad8332

Browse files
jrngitster
authored andcommitted
t0001: test git init when run via an alias
Add some tests to document the correct behavior of (possibly aliased) init when run within and outside a git directory. If I set up a simple git alias “quietinit = init --quiet”, usually it will work just like ‘git init --quiet’. There are some differences, unfortunately, since in the process of checking for aliases, git has to look for a .git/config file. If ‘git quietinit’ is run from a subdirectory of an existing git repository, that repository’s configuration will affect the configuration of the new repository. In particular, the new repository can inherit bogus values for core.bare and core.worktree. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8351836 commit 4ad8332

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

t/t0001-init.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,62 @@ test_expect_success 'plain' '
3333
check_config plain/.git false unset
3434
'
3535

36+
test_expect_success 'plain nested in bare' '
37+
(
38+
unset GIT_DIR GIT_WORK_TREE &&
39+
git init --bare bare-ancestor.git &&
40+
cd bare-ancestor.git &&
41+
mkdir plain-nested &&
42+
cd plain-nested &&
43+
git init
44+
) &&
45+
check_config bare-ancestor.git/plain-nested/.git false unset
46+
'
47+
48+
test_expect_success 'plain through aliased command, outside any git repo' '
49+
(
50+
unset GIT_DIR GIT_WORK_TREE GIT_CONFIG_NOGLOBAL &&
51+
HOME=$(pwd)/alias-config &&
52+
export HOME &&
53+
mkdir alias-config &&
54+
echo "[alias] aliasedinit = init" >alias-config/.gitconfig &&
55+
56+
GIT_CEILING_DIRECTORIES=$(pwd) &&
57+
export GIT_CEILING_DIRECTORIES &&
58+
59+
mkdir plain-aliased &&
60+
cd plain-aliased &&
61+
git aliasedinit
62+
) &&
63+
check_config plain-aliased/.git false unset
64+
'
65+
66+
test_expect_failure 'plain nested through aliased command' '
67+
(
68+
unset GIT_DIR GIT_WORK_TREE &&
69+
git init plain-ancestor-aliased &&
70+
cd plain-ancestor-aliased &&
71+
echo "[alias] aliasedinit = init" >>.git/config &&
72+
mkdir plain-nested &&
73+
cd plain-nested &&
74+
git aliasedinit
75+
) &&
76+
check_config plain-ancestor-aliased/plain-nested/.git false unset
77+
'
78+
79+
test_expect_failure 'plain nested in bare through aliased command' '
80+
(
81+
unset GIT_DIR GIT_WORK_TREE &&
82+
git init --bare bare-ancestor-aliased.git &&
83+
cd bare-ancestor-aliased.git &&
84+
echo "[alias] aliasedinit = init" >>config &&
85+
mkdir plain-nested &&
86+
cd plain-nested &&
87+
git aliasedinit
88+
) &&
89+
check_config bare-ancestor-aliased.git/plain-nested/.git false unset
90+
'
91+
3692
test_expect_success 'plain with GIT_WORK_TREE' '
3793
if (
3894
unset GIT_DIR

0 commit comments

Comments
 (0)