git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] branch: delete now accepts '-' as branch name
@ 2022-02-16 14:08 Erlend Egeberg Aasland via GitGitGadget
  2022-02-16 16:54 ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Erlend Egeberg Aasland via GitGitGadget @ 2022-02-16 14:08 UTC (permalink / raw)
  To: git; +Cc: Erlend Egeberg Aasland, Erlend E. Aasland

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-02-22 11:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 14:08 [PATCH] branch: delete now accepts '-' as branch name Erlend Egeberg Aasland via GitGitGadget
2022-02-16 16:54 ` 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

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).