-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg-depend.sh
71 lines (55 loc) · 1.39 KB
/
tg-depend.sh
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
#!/bin/sh
# TopGit - A different patch queue manager
# (c) Petr Baudis <[email protected]> 2008
# GPLv2
name=
usage()
{
echo "Usage: tg [...] depend add NAME" >&2
exit 1
}
## Parse options
subcmd="$1"; shift || :
case "$subcmd" in
-h|"")
usage;;
add)
;;
*)
die "unknown subcommand ($subcmd)";;
esac
while [ -n "$1" ]; do
arg="$1"; shift
case "$arg" in
-*)
usage;;
*)
[ -z "$name" ] || die "name already specified ($name)"
name="$arg";;
esac
done
## Sanity checks
[ -n "$name" ] || die "no branch name specified"
branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
die "invalid branch name: $name"
# Check that we are on a TopGit branch.
current_name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
current_base_rev="$(git rev-parse --short --verify "refs/top-bases/$current_name" 2>/dev/null)" ||
die "not a TopGit-controlled branch"
## Record new dependency
depend_add()
{
[ "$name" = "$current_name" ] &&
die "$name cannot depend on itself."
{ $tg summary --deps; echo "$current_name" "$name"; } |
tsort >/dev/null ||
die "tg: that dependency would introduce a dependency loop"
grep -F -x -e "$name" "$root_dir/.topdeps" >/dev/null &&
die "tg: $current_name already depends on $name"
echo "$name" >>"$root_dir/.topdeps"
git add -f "$root_dir/.topdeps"
git commit -m"New TopGit dependency: $name"
$tg update
}
depend_$subcmd
# vim:noet