Repository navigation
Expand file tree
/
Copy pathsubmodule-symlinks.sh
More file actions
93 lines (93 loc) · 3.63 KB
/
Copy pathsubmodule-symlinks.sh
File metadata and controls
93 lines (93 loc) · 3.63 KB
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
#!/usr/bin/env bash
set -eu
args=("$@")
# shellcheck source=tests/fixtures/submodule-layout.sh
source "$(dirname "${BASH_SOURCE[0]}")/submodule-layout.sh" "$1" "$2"
scenario=${args[2]}
kind=${args[3]}
dangling=${args[4]}
relative_target=${args[6]}
modules="$root/parent/.git/modules"
target="$root/outside"
case "$scenario" in
test_submodule_writes_use_checked_worktree)
if test "${args[5]}" = update; then
printf updated > parent/module/file
git -C parent/module add file
git -C parent/module commit -qm 'Advance submodule'
git -C parent add module
git -C parent commit -qm 'Record updated submodule'
git -C parent/module reset -q --hard HEAD^
fi
mkdir "$target"
ln -s "$target" parent/redirect
worktree="$root/parent/redirect"
if test "$kind" = intermediate; then
mkdir "$target/worktree"
worktree="$worktree/worktree"
fi
printf content > "$worktree/file"
git -C parent/module config core.worktree "$worktree"
;;
test_move_leaf_symlink_compatibility)
case "$kind" in
empty|nonempty) mkdir "$target" ;;
file) printf keep > "$target" ;;
esac
if test "$kind" = nonempty; then printf keep > "$target/keep"; fi
ln -s "$target" parent/destination
;;
test_clone_rejects_checkout_symlinks)
if test "$dangling" = False; then mkdir "$target"; fi
ln -s "$target" parent/link
;;
test_submodule_rejects_checkout_and_gitmodules_symlinks)
path=parent/module
if test "$kind" = gitmodules; then path=parent/.gitmodules; fi
mv "$path" "$target"
ln -s "$target" "$path"
mkdir parent/moved
;;
test_submodule_allows_symlink_above_worktree)
ln -s "$root/parent" alias
;;
test_submodule_allows_metadata_destination_symlinks)
mkdir "$target"
ln -s "$target" "$modules/link"
;;
test_submodule_allows_existing_metadata_symlinks|test_remove_linked_metadata_keeps_siblings_and_can_reinitialize)
if test "$scenario" = test_remove_linked_metadata_keeps_siblings_and_can_reinitialize; then
git -C parent submodule add --name nested/sibling "$source" sibling
git -C parent commit -qm 'Add sibling'
fi
case "$kind" in
modules) link="$modules" ;;
intermediate) link="$modules/nested" ;;
leaf) link="$modules/nested/module" ;;
gitfile) link="$root/parent/module/.git" ;;
config) link="$modules/nested/module/config" ;;
alias)
link="$modules/alias"
target="$modules/nested"
printf 'gitdir: ../.git/modules/alias/module' > parent/module/.git
;;
esac
if test "$kind" != alias; then mv "$link" "$target"; fi
ln -s "$target" "$link"
git config --file "$modules/nested/module/config" core.worktree "$root/parent/module"
if test "$scenario" = test_remove_linked_metadata_keeps_siblings_and_can_reinitialize; then
git config --file "$modules/nested/sibling/config" core.worktree "$root/parent/sibling"
fi
;;
test_add_to_dangling_metadata_symlink)
target="$root/missing/metadata"
# Windows determines the native symlink type from the existing target.
mkdir -p "$target"
if test "$relative_target" = True; then
ln -s ../../../missing/metadata "$modules/new"
else
ln -s "$target" "$modules/new"
fi
rmdir "$target" "$root/missing"
;;
esac