aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gitalias/git-sw.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gitalias/git-sw.go')
-rw-r--r--src/gitalias/git-sw.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gitalias/git-sw.go b/src/gitalias/git-sw.go
index f4cab21..78f7397 100644
--- a/src/gitalias/git-sw.go
+++ b/src/gitalias/git-sw.go
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"strings"
+ "unicode"
)
func main() {
@@ -12,10 +13,17 @@ func main() {
if requiresDetachFlag(os.Args) {
gitArgs = append(gitArgs, "--detach")
}
+ firstPositionalArg := true
for i, argv := range os.Args {
if i == 0 {
continue // argv[0] is a program name.
}
+ if firstPositionalArg && !strings.HasPrefix(argv, "-") {
+ if isInt(argv) {
+ argv = "feature/" + argv
+ }
+ firstPositionalArg = false
+ }
gitArgs = append(gitArgs, argv)
}
@@ -45,3 +53,12 @@ func requiresDetachFlag(argv []string) bool {
firstArg := argv[1]
return strings.HasPrefix(firstArg, "origin/") || strings.HasPrefix(firstArg, "upstream/")
}
+
+func isInt(s string) bool {
+ for _, c := range s {
+ if !unicode.IsDigit(c) {
+ return false
+ }
+ }
+ return true
+}