2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2015
8 USAGE
="Usage: ${tgname:-tg} [...] depend add [--no-update | --no-commit] <name>..."
14 printf '%s\n' "$USAGE" >&2
27 die
"unknown subcommand ($subcmd)";;
44 names
="${names:+$names }$arg";;
51 [ -n "$names" ] || die
"no branch name specified"
55 name
="${oldnames%% *}"
56 oldnames
="${oldnames#* }"
59 case " $names " in *" $name "*) continue; esac
60 git rev-parse
--quiet --verify "refs/heads/$name" -- >/dev
/null ||
61 die
"invalid branch name: $name"
62 names
="${names:+$names }$name"
66 # Check that we are on a TopGit branch.
67 v_verify_topgit_branch current_name HEAD
71 [ "$current_name" != "$_dep" ] ||
72 die
"$tgname: that dependency ($newly_added) would introduce a dependency loop"
77 [ "$1" != "$current_name" ] ||
78 die
"$current_name cannot depend on itself."
79 ! grep -F -q -x -e "$1" "$root_dir/.topdeps" ||
80 die
"$tgname: $current_name already depends on $1"
81 # deps can be non-tgish but we can't run recurse_deps() on them
82 ref_exists
"refs/$topbases/$1" ||
return 0
85 recurse_deps check_cycle_name
"$newly_added"
88 ## Record new dependency
91 [ -z "$(git status --porcelain -- :/.topdeps)" ] ||
92 die
".topdeps has uncommitted changes"
93 # We are "read-only" and cacheable until the first change
96 for name
in $names; do
99 [ -n "$nocommit" ] || ensure_ident_available
100 newdepsfile
="$(get_temp newdeps)"
101 ! [ -e "$root_dir/.topdeps" ] ||
awk '{print}' <"$root_dir/.topdeps" >"$newdepsfile"
102 for name
in $names; do
103 echol
"$name" >>"$newdepsfile"
105 cat "$newdepsfile" >"$root_dir/.topdeps"
106 git add
-f "$root_dir/.topdeps"
109 msg
=".topdeps: add dependencies: $names";;
111 msg
=".topdeps: add new dependency $name";;
113 [ -z "$nocommit" ] ||
{
114 [ -s "$git_dir/MERGE_MSG" ] ||
printf '%s\n' "$msg" >"$git_dir/MERGE_MSG"
115 info
"updated .topdeps and staged the change"
116 info
"run \`git commit\` then \`tg update\` to complete addition"
120 git commit
-m "$msg" "$root_dir/.topdeps"
121 [ -z "$noupdate" ] ||
{
122 info
"be sure to run \`tg update\` at some point"
125 (ensure_clean_tree
) ||
{
126 warn
"skipping needed \`tg update\` since working directory is dirty"
127 warn
"be sure to run \`tg update\` when working directory is clean"
130 set -- "$current_name"
131 .
"$TG_INST_CMDDIR"/tg-update