2 # TopGit - A different patch queue manager
3 # (C) Petr Baudis <pasky@suse.cz> 2008
4 # (C) Per Cederqvist <ceder@lysator.liu.se> 2010
5 # (C) Kyle J. McKay <mackyle@gmail.com> 2017
9 force
= # Whether to annihilate non-empty branch, or branch where only the base is left.
10 update
=1 # Whether to run tg update on affected branches
11 stash
= # tgstash refs before changes
14 if [ "$(git config --get --bool topgit.autostash 2>/dev/null)" != "false" ]; then
15 # topgit.autostash is true (or unset)
35 echo "Usage: ${tgname:-tg} [...] annihilate [-f] [--no-update] [<name>]" >&2
38 [ -z "$name" ] || die
"name already specified ($name)"
46 v_verify_topgit_branch name
${name:-HEAD}
47 ! branch_annihilated
"$name" || die
"TopGit branch $name is already annihilated."
49 [ -z "$force" ] && { branch_empty
"$name" || die
"branch is non-empty: $name"; }
51 if [ -z "$(git symbolic-ref -q HEAD)" ] ||
52 [ "$(git rev-parse --verify --quiet HEAD --)" != "$(git rev-parse --verify --quiet "refs
/heads
/$name^
0" --)" ]; then
53 info
"switching to branch $name"
54 git checkout
"$name" ||
exit 1
60 ensure_ident_available
61 alldeps
="$(get_temp alldeps)"
62 tg
--no-pager summary
--deps >"$alldeps" || die
"tg summary --deps failed"
64 # always auto stash even if it's just to the anonymous stash TG_STASH
66 stashbr
="$(awk -v annb="$name" '
68 if ($1 == annb && $2 != "" && $2 != annb) print $2
69 if ($2 == annb && $1 != "" && $1 != annb) print $1
71 ' <"$alldeps" | sort -u)"
72 stashmsg
="tgannihilate: autostash before annihilate branch $name"
73 if [ -n "$stash" ]; then
74 tg tag
-q -q -m "$stashmsg" --stash $name $stashbr &&
75 stashhash
="$(git rev-parse --quiet --verify refs/tgstash --)" &&
76 [ -n "$stashhash" ] &&
77 [ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
78 die
"requested --stash failed"
80 tg tag
--anonymous $name $stashbr &&
81 stashhash
="$(git rev-parse --quiet --verify TG_STASH --)" &&
82 [ -n "$stashhash" ] &&
83 [ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
84 die
"anonymous --stash failed"
87 mb
="$(git merge-base "refs
/$topbases/$name" "refs
/heads
/$name")"
88 git read-tree
"$mb^{tree}"
89 # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run,
90 # which would bark upon missing .top* files.
91 git commit
--no-verify -m"TopGit branch $name annihilated."
93 # Propagate the dependencies through to dependents (if any), if they don't already have them
94 dependencies
="$(awk -v annb="$name" 'NF == 2 && $2 != "" && $1 == annb { print $2 }' <"$alldeps")"
96 while read dependent
&& [ -n "$dependent" ]; do
97 # to avoid ambiguity with checkout -f we must use symbolic-ref + reset
98 git symbolic-ref HEAD
"refs/heads/$dependent"
101 while read dependency
&& [ -n "$dependency" ]; do
102 ! tg depend add
--no-update "$dependency" >/dev
/null
2>&1 || needupdate
=1
106 [ -z "$needupdate" ] || updatelist
="${updatelist:+$updatelist }$dependent"
108 $(awk -v annb="$name" 'NF == 2 && $1 != "" && $2 == annb { print $1 }' <"$alldeps")
111 info
"branch successfully annihilated: $name"
113 if [ -n "$updatelist" ]; then
114 if [ -n "$update" ]; then
115 now
="after the update completes"
117 info
"skipping update because --no-update given"
118 info
"be sure to update affected branches: $updatelist"
122 info
"If you have shared your work, you might want to run ${tgname:-tg} push $name $now."
123 if [ -n "$updatelist" ] && [ -n "$update" ]; then
124 info
"now updating affected branches: $updatelist"
126 .
"$TG_INST_CMDDIR"/tg-update