summaryrefslogtreecommitdiffstats
path: root/src/subgit-subrepo
blob: d1271e200141415d8b35025b0aa5d732786a7ab9 (plain) (blame)
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
#!/bin/sh

# Return either the subrepo path for each path or all
# subrepo paths in the current subgit container.

usage() {
	die $(cat <<-EOF
	Usage: subgit subrepo [PATH..]

	  Resolves and returns absolute paths to subrepositories. With no
	  arguments, lists all subrepos in current container. With arguments,
	  normalizes each path to its tracked subrepo root.
	EOF
	)
}

while [ "$1" ]; do
	case $1 in
	-h) usage;;
	--) shift; break;;
	-*) die "Invalid option $1";;
	*) break;;
	esac
done

subrepos=()
if [ $# -eq 0 ]; then
	root=$(subgit-sub root)
	source "$root/.subgitrc"
	for relpath in "${!subgit[@]}"; do
		subrepos+=("$root/$relpath")
	done
else
	for arg in "$@"; do
		root=$(subgit-sub parent "$arg")
		relpath=$(subgit-sub relpath "$root" "$arg")
		subrepos+=("$root/$relpath")
	done
fi

for subrepo in ${subrepos[@]}; do
	echo "$subrepo"
done