From 616d202b75034d7a6a6c8f6e88e636cd93b38270 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 13 Jul 2023 00:57:55 +0900 Subject: git:git-sw: add "-d" flag if the given ref seems to be commit hash --- src/gitalias/git-sw.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gitalias/git-sw.go b/src/gitalias/git-sw.go index 78f7397..5c098a1 100644 --- a/src/gitalias/git-sw.go +++ b/src/gitalias/git-sw.go @@ -51,7 +51,23 @@ func requiresDetachFlag(argv []string) bool { return false } firstArg := argv[1] - return strings.HasPrefix(firstArg, "origin/") || strings.HasPrefix(firstArg, "upstream/") + + // Example: origin/main, upstream/develop + if strings.HasPrefix(firstArg, "origin/") || strings.HasPrefix(firstArg, "upstream/") { + return true + } + + // Example: 1234, cafebabe + if len(firstArg) >= 4 { + for _, c := range firstArg { + if !unicode.Is(unicode.ASCII_Hex_Digit, c) { + return false + } + } + return true + } + + return false } func isInt(s string) bool { -- cgit v1.2.3-70-g09d2