chiark / gitweb /
put die() messages to stderr
[topgit.git] / tg-depend.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz>  2008
4 # GPLv2
5
6 name=
7
8
9 usage()
10 {
11     echo "Usage: tg [...] depend add NAME" >&2
12     exit 1
13 }
14
15 ## Parse options
16
17 subcmd="$1"; shift || :
18 case "$subcmd" in
19         -h|"")
20                 usage;;
21         add)
22                 ;;
23         *)
24                 die "unknown subcommand ($subcmd)";;
25 esac
26
27 while [ -n "$1" ]; do
28         arg="$1"; shift
29         case "$arg" in
30         -*)
31                 usage;;
32         *)
33                 [ -z "$name" ] || die "name already specified ($name)"
34                 name="$arg";;
35         esac
36 done
37
38
39 ## Sanity checks
40
41 [ -n "$name" ] || die "no branch name specified"
42 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
43         die "invalid branch name: $name"
44
45 # Check that we are on a TopGit branch.
46 current_name="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
47 current_base_rev="$(git rev-parse --short --verify "refs/top-bases/$current_name" 2>/dev/null)" ||
48         die "not a TopGit-controlled branch"
49
50 ## Record new dependency
51 depend_add()
52 {
53         [ "$name" = "$current_name" ] &&
54                 die "$name cannot depend on itself."
55
56         { $tg summary --deps; echo "$current_name" "$name"; } |
57                 tsort >/dev/null ||
58                 die "tg: that dependency would introduce a dependency loop"
59
60         grep -F -x -e "$name" "$root_dir/.topdeps" >/dev/null &&
61                 die "tg: $current_name already depends on $name"
62
63         echo "$name" >>"$root_dir/.topdeps"
64         git add -f "$root_dir/.topdeps"
65         git commit -m"New TopGit dependency: $name"
66         $tg update
67 }
68
69 depend_$subcmd
70
71 # vim:noet