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)";;
43 names
="${names:+$names }$arg";;
50 [ -n "$names" ] || die
"no branch name specified"
54 name
="${oldnames%% *}"
55 oldnames
="${oldnames#* }"
58 case " $names " in *" $name "*) continue; esac
59 git rev-parse
--quiet --verify "refs/heads/$name" -- >/dev
/null ||
60 die
"invalid branch name: $name"
61 names
="${names:+$names }$name"
65 # Check that we are on a TopGit branch.
66 current_name
="$(verify_topgit_branch HEAD)"
70 [ "$current_name" != "$_dep" ] ||
71 die
"$tgname: that dependency ($newly_added) would introduce a dependency loop"
76 [ "$1" != "$current_name" ] ||
77 die
"$current_name cannot depend on itself."
78 ! grep -F -q -x -e "$1" "$root_dir/.topdeps" ||
79 die
"$tgname: $current_name already depends on $1"
80 # deps can be non-tgish but we can't run recurse_deps() on them
81 ref_exists
"refs/$topbases/$1" ||
return 0
84 recurse_deps check_cycle_name
"$newly_added"
87 ## Record new dependency
90 [ -z "$(git status --porcelain -- :/.topdeps)" ] ||
91 die
".topdeps has uncommitted changes"
92 # We are "read-only" and cacheable until the first change
95 for name
in $names; do
98 [ -n "$nocommit" ] || ensure_ident_available
99 for name
in $names; do
100 echol
"$name" >>"$root_dir/.topdeps"
102 git add
-f "$root_dir/.topdeps"
105 msg
=".topdeps: add dependencies: $names";;
107 msg
=".topdeps: add new dependency $name";;
109 [ -z "$nocommit" ] ||
{
110 [ -s "$git_dir/MERGE_MSG" ] ||
printf '%s\n' "$msg" >"$git_dir/MERGE_MSG"
111 info
"updated .topdeps and staged the change"
112 info
"run \`git commit\` then \`tg update\` to complete addition"
116 git commit
-m "$msg" "$root_dir/.topdeps"
117 [ -z "$noupdate" ] ||
{
118 info
"be sure to run \`tg update\` at some point"
121 (ensure_clean_tree
) ||
{
122 warn
"skipping needed \`tg update\` since worktree is dirty"
123 warn
"be sure to run \`tg update\` when worktree is clean"
126 set -- "$current_name"
127 .
"$TG_INST_CMDDIR"/tg-update