-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-git-new-workdir-recursive
executable file
·119 lines (89 loc) · 3.44 KB
/
test-git-new-workdir-recursive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
set -e
die () {
echo $@
exit 1
}
base=/tmp/test/test-git-new-workdir-recursive
mkdir -p ${base}
cd ${base}
rm -rf some repo1 repo2 file
### Create a repository which we'll add as a submodule later.
# Make sure the submodule is not on the same level as repo1 and repo2, or
# you'll think unsetting core.worktree isn't needed.
mkdir -p 'some/path/with spaces/repo'
cd 'some/path/with spaces/repo'
git init -q
touch file1
git add file1
git commit -q -m file1
cd ${base}
### Create a repository which we'll try to create workdirs for later.
mkdir -p repo1
cd repo1
git init -q
### Add submodules to the repository, with varying degrees of trickyness.
# submodule1 has spaces and dots.
git submodule -q add "${base}/some/path/with spaces/repo" 'sub.module 1'
# submodule2 is uninitialised.
git submodule -q add "${base}/some/path/with spaces/repo" 'sub.module 2'
git submodule -q deinit --force 'sub.module 2'
# submodule3 has update=none.
git submodule -q add "${base}/some/path/with spaces/repo" 'sub.module 3'
git config 'submodule.sub.module 3.update' none
# submodule4 has non-existing path.
# TODO. Not sure what behaviour should be.
#git submodule -q add -f "${base}/some/path/with spaces/repo" 'sub.module 4'
#git config 'submodule.sub.module 4.url' "${base}/some/path/that/does/not/exist"
git add .gitmodules
git commit -q -m submodules
cd ${base}
### Run the script
git new-workdir-recursive repo1 repo2
### Running it twice should work.
git new-workdir-recursive repo1 repo2
### Sanity check
touch file
git new-workdir-recursive repo1 file >/dev/null 2>&1 && die Overwriting a file should fail.
echo "Ok 'Sanity check'"
### Only submodule1
# submodule2 and submodule3 should not have a workdir yet
cd "${base}/repo2/sub.module 1"
test $(ls -a1 "${base}/repo2/sub.module 2" | wc -l) -eq 2 || die 'repo2/sub.module 2' not empty
test $(ls -a1 "${base}/repo2/sub.module 3" | wc -l) -eq 2 || die 'repo2/sub.module 3' not empty
echo "Ok 'Only submodule1'"
### Branches are shared, checkouts are not
# A new branch in the new submodule workdir should also exist in the original
# submodule, but not be checked out.
cd "${base}/repo2/sub.module 1"
git checkout -q -b branch1
cd "${base}/repo1/sub.module 1"
git branch | grep -q 'branch1' || die no branch1
git branch | grep '* branch1' && die branch1 checked out! || true
echo "Ok 'Branches are shared, checkouts are not'"
### submodule init
# After only initialising (not updating), submodules are still empty, so they
# should be skipped, or git-new-workdir will link files from the parent repo
# .git directory.
cd "${base}/repo1"
git submodule -q init 'sub.module 2'
cd ${base}
git new-workdir-recursive repo1 repo2
test $(ls -a1 "${base}/repo2/sub.module 2"| grep -v file1 | wc -l) -eq 2 || die 'repo2/sub.module 2' contains nonsense
echo "Ok 'submodule init'"
### submodule update
# After updating submodule2, a workdir should be created
cd "${base}/repo1"
git submodule -q update 'sub.module 2'
cd ${base}
git new-workdir-recursive repo1 repo2
test $(ls -a1 "${base}/repo2/sub.module 2" | wc -l) -gt 2 || die 'repo2/sub.module 2' still empty
echo "Ok 'submodule update'"
### update=checkout
# After setting submodule3 to update=checkout, a workdir should be created
cd "${base}/repo1"
git config 'submodule.sub.module 3.update' checkout
cd ${base}
git new-workdir-recursive repo1 repo2
test $(ls -a1 "${base}/repo2/sub.module 3" | wc -l) -gt 2 || die 'repo2/sub.module 3' still empty
echo "Ok 'update=checkout update'"
echo Done