diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-27 04:43:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-27 04:43:10 +0900 |
| commit | 9fe7ae1fa6e4f1615f18094bd4d315316eec17d9 (patch) | |
| tree | 9a73c4743b462f013de67a81025f1453e8172116 | |
| parent | 61742fdbdd55cb383ddb3d5037659f50a751111e (diff) | |
| download | dotfiles-9fe7ae1fa6e4f1615f18094bd4d315316eec17d9.tar.gz dotfiles-9fe7ae1fa6e4f1615f18094bd4d315316eec17d9.tar.zst dotfiles-9fe7ae1fa6e4f1615f18094bd4d315316eec17d9.zip | |
git: remove src/gitalias/* from this repository
| -rw-r--r-- | README | 3 | ||||
| -rw-r--r-- | src/gitalias/git-extract-issue.go | 38 | ||||
| -rw-r--r-- | src/gitalias/git-sw.go | 80 |
3 files changed, 3 insertions, 118 deletions
@@ -32,6 +32,9 @@ $ cargo install alacritty $ cd ~/src/reparojson $ cargo install --path . + +$ cd ~/src/git-helpers +$ go install ./cmd/... ``` ## PC 168 diff --git a/src/gitalias/git-extract-issue.go b/src/gitalias/git-extract-issue.go deleted file mode 100644 index 4681d4d..0000000 --- a/src/gitalias/git-extract-issue.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "fmt" - "os" - "regexp" -) - -func main() { - argv := os.Args - argc := len(argv) - if argc != 2 { - return - } - branchName := argv[1] - fmt.Println(extractIssueNumberFromBranchName(branchName)) -} - -// * 123 => #123 -// * 123-suffix => #123 -// * feature/123 => #123 -// * feature/123-suffix => #123 -// * feature/prefix-123 => prefix-123 -// * feature/prefix-123-suffix => prefix-123 -func extractIssueNumberFromBranchName(branchName string) string { - pattern := regexp.MustCompile(`\A(?:\w+/)?(\w+-)?(\d+)(?:-\w+)*\z`) - matches := pattern.FindSubmatch([]byte(branchName)) - if len(matches) != 3 { - return "" - } - var prefix string - if len(matches[1]) == 0 { - prefix = "#" - } else { - prefix = string(matches[1]) - } - return prefix + string(matches[2]) -} diff --git a/src/gitalias/git-sw.go b/src/gitalias/git-sw.go deleted file mode 100644 index 5c098a1..0000000 --- a/src/gitalias/git-sw.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "log" - "os" - "os/exec" - "strings" - "unicode" -) - -func main() { - gitArgs := []string{"switch"} - 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) - } - - cmd := exec.Command("git", gitArgs...) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - err := cmd.Run() - if err != nil { - switch err.(type) { - case *exec.ExitError: - // Do nothing here because Git has already reported the error. - default: - log.Fatal(err) - } - } - - os.Exit(cmd.ProcessState.ExitCode()) -} - -func requiresDetachFlag(argv []string) bool { - argc := len(argv) - if argc == 1 { - return false - } - firstArg := argv[1] - - // 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 { - for _, c := range s { - if !unicode.IsDigit(c) { - return false - } - } - return true -} |
