Permalink
Browse files

Do basic error checking in "tg depend add"

Check for the following errors:

 - Working on a non-TopGit branch.
 - Adding a branch as a dependency of itself.
 - Adding a dependency that introduces a loop.
 - Adding a dependency that already exists.

Signed-off-by: Per Cederqvist <ceder@lysator.liu.se>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
  • Loading branch information...
1 parent 880c0f8 commit 9404aa1ac356646adf93d1761263031efa570dc5 @cederlys cederlys committed with Uwe Kleine-König Sep 6, 2010
Showing with 15 additions and 0 deletions.
  1. +15 −0 tg-depend.sh
View
@@ -42,9 +42,24 @@ done
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"

0 comments on commit 9404aa1

Please sign in to comment.