From bd01f01331f2b70316d694325931db051b91dd69 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 17 Nov 2015 11:41:58 -0800 Subject: [PATCH] tg-delete.sh: double -f will delete your HEAD Signed-off-by: Kyle J. McKay --- README | 4 ++++ tg-delete.sh | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README b/README index b6f2c34..bda473e 100644 --- a/README +++ b/README @@ -367,6 +367,10 @@ tg delete certain TopGit commands complain, because the base of branch B is still there. + Normally ``tg delete`` will refuse to delete the current branch. + However, giving ``-f`` twice (or more) will force it to do so but it + will first detach your HEAD. + IMPORTANT: Currently, this command will *NOT* remove the branch from the dependency list in other branches. You need to take care of this *manually*. This is even more complicated in diff --git a/tg-delete.sh b/tg-delete.sh index d95c131..201207b 100644 --- a/tg-delete.sh +++ b/tg-delete.sh @@ -13,7 +13,7 @@ while [ -n "$1" ]; do arg="$1"; shift case "$arg" in -f|--force) - force=1;; + force=$(( $force +1 ));; -*) echo "Usage: ${tgname:-tg} [...] delete [-f] " >&2 exit 1;; @@ -35,8 +35,11 @@ branchrev="$(git rev-parse --verify "$name" -- 2>/dev/null)" || fi baserev="$(git rev-parse --verify "refs/top-bases/$name" -- 2>/dev/null)" || die "not a TopGit topic branch: $name" -! headsym="$(git symbolic-ref -q HEAD)" || [ "$headsym" != "refs/heads/$name" ] || - die "cannot delete your current branch" +! headsym="$(git symbolic-ref -q HEAD)" || [ "$headsym" != "refs/heads/$name" ] || { + [ -n "$force" ] && [ "$force" -ge 2 ] || die "cannot delete your current branch" + warn "detaching HEAD to delete current branch" + git checkout --quiet --detach || : +} [ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; } -- 2.11.4.GIT