From: "Erlend Egeberg Aasland via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Erlend Egeberg Aasland <erlend.aasland@innova.no>,
"Erlend E. Aasland" <erlend.aasland@innova.no>
Subject: [PATCH] branch: delete now accepts '-' as branch name
Date: Wed, 16 Feb 2022 14:08:14 +0000 [thread overview]
Message-ID: <pull.1217.git.git.1645020495014.gitgitgadget@gmail.com> (raw)
From: "Erlend E. Aasland" <erlend.aasland@innova.no>
This makes it easy to get rid of short-lived branches:
$ git switch -c experiment
$ git switch -
$ git branch -D -
$ gh pr checkout nnn
$ make && make test
$ git switch -
$ git branch -D -
Signed-off-by: Erlend E. Aasland <erlend.aasland@innova.no>
---
[RFC] branch: delete now accepts '-' as branch name
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1217%2Ferlend-aasland%2Fbranch-name-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1217/erlend-aasland/branch-name-v1
Pull-Request: https://github.com/git/git/pull/1217
builtin/branch.c | 6 +++++-
t/t3200-branch.sh | 8 ++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 4ce2a247542..f6c876c09d2 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -236,7 +236,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
char *target = NULL;
int flags = 0;
- strbuf_branchname(&bname, argv[i], allowed_interpret);
+ if (!strcmp(argv[i], "-")) {
+ strbuf_branchname(&bname, "@{-1}", allowed_interpret);
+ } else {
+ 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 1bc3795847d..6afb7150534 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -71,6 +71,14 @@ test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
test_must_fail git reflog exists refs/heads/d/e/f
'
+test_expect_success 'git branch -D - should delete branch @{-1}' '
+ git switch -c j &&
+ git switch - &&
+ git branch -D - &&
+ test_path_is_missing .git/refs/heads/j &&
+ test_must_fail git reflog exists refs/heads/j
+'
+
test_expect_success 'git branch j/k should work after branch j has been deleted' '
git branch j &&
git branch -d j &&
base-commit: b80121027d1247a0754b3cc46897fee75c050b44
--
gitgitgadget
next reply other threads:[~2022-02-16 14:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 14:08 Erlend Egeberg Aasland via GitGitGadget [this message]
2022-02-16 16:54 ` [PATCH] branch: delete now accepts '-' as branch name Junio C Hamano
2022-02-16 19:03 ` Eric Sunshine
2022-02-16 19:41 ` Junio C Hamano
2022-02-16 23:06 ` Erlend Aasland
2022-02-17 17:13 ` Eric Sunshine
2022-02-17 18:41 ` Junio C Hamano
2022-02-21 16:34 ` Ævar Arnfjörð Bjarmason
2022-02-21 17:13 ` Junio C Hamano
2022-02-21 19:20 ` Ævar Arnfjörð Bjarmason
2022-02-22 11:05 ` Erlend Aasland
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=pull.1217.git.git.1645020495014.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=erlend.aasland@innova.no \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.