From: Aaron Greenberg <p@aaronjgreenberg.com>
To: git@vger.kernel.org
Cc: peff@peff.net, p@aaronjgreenberg.com
Subject: [PATCH] branch: implement shortcut to delete last branch
Date: Fri, 23 Mar 2018 02:09:26 +0000 [thread overview]
Message-ID: <1521770966-18383-2-git-send-email-p@aaronjgreenberg.com> (raw)
In-Reply-To: <1521770966-18383-1-git-send-email-p@aaronjgreenberg.com>
Add support for using the "-" shortcut to delete the last checked-out
branch. This functionality already exists for git-merge, git-checkout,
and git-revert.
Signed-off-by: Aaron Greenberg <p@aaronjgreenberg.com>
---
builtin/branch.c | 3 +++
t/t3200-branch.sh | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/builtin/branch.c b/builtin/branch.c
index 6d0cea9..9e37078 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -221,6 +221,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
char *target = NULL;
int flags = 0;
+ if (!strcmp(argv[i], "-"))
+ argv[i] = "@{-1}";
+
strbuf_branchname(&bname, argv[i], allowed_interpret);
free(name);
name = mkpathdup(fmt, bname.buf);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 6c0b7ea..a3ffd54 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -776,6 +776,15 @@ test_expect_success 'deleting currently checked out branch fails' '
test_must_fail git branch -d my7
'
+test_expect_success 'test deleting last branch' '
+ git checkout -b my7.2 &&
+ git checkout - &&
+ sha1=$(git rev-parse my7 | cut -c 1-7) &&
+ echo "Deleted branch my7.2 (was $sha1)." >expect &&
+ git branch -d - >actual 2>&1 &&
+ test_i18ncmp expect actual
+'
+
test_expect_success 'test --track without .fetch entries' '
git branch --track my8 &&
test "$(git config branch.my8.remote)" &&
--
2.7.4
next prev parent reply other threads:[~2018-03-23 2:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 2:09 [PATCH] branch: implement shortcut to delete last branch Aaron Greenberg
2018-03-23 2:09 ` Aaron Greenberg [this message]
2018-03-23 8:56 ` Jeff King
2018-03-23 9:00 ` Jeff King
2018-03-23 22:40 ` [PATCH v2] " Aaron Greenberg
2018-03-23 22:40 ` [PATCH] " Aaron Greenberg
2018-03-26 8:10 ` [PATCH v2] " Jeff King
2018-03-26 12:41 ` git
2018-03-26 16:49 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2018-03-27 18:46 [PATCH] " Aaron Greenberg
2018-03-27 18:46 ` Aaron Greenberg
2018-03-27 19:11 ` Jonathan Nieder
2018-03-27 19:23 ` Ævar Arnfjörð Bjarmason
2018-03-27 19:26 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1521770966-18383-2-git-send-email-p@aaronjgreenberg.com \
--to=p@aaronjgreenberg.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).