-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1038c94
commit 1c4b465
Showing
3 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
# git-rm-merged | ||
|
||
**ALERT** Not implemented yet 🤷♂️ | ||
git-rm-merged is git subcommand that removes the merged local branches. | ||
|
||
The git sub command that removes the merged local branches. | ||
## Description | ||
|
||
## Usage | ||
You can use the `git-rm-merged` as a git subcommand. | ||
This removes the merged local branches. | ||
|
||
**This confirms if you want to delete the target branches.** | ||
|
||
`rm-merged` removes the merged local branches. | ||
## Install | ||
|
||
``` | ||
git rm-merged | ||
go get -u github.com/yasukotelin/git-rm-merged | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
$ git rm-merged | ||
feature/#1 [y/n]:y | ||
feature/#2 [y/n]:n | ||
feature/#3 [y/n]:y | ||
``` | ||
|
||
## Licence | ||
|
||
MIT | ||
|
||
## Author | ||
|
||
yasukotelin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func getMergedBranches() ([]string, error) { | ||
var branches []string | ||
out, err := exec.Command("git", "branch", "--merged").Output() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, branch := range strings.Split(string(out), "\n") { | ||
branch = strings.TrimSpace(branch) | ||
if (branch == "") { | ||
continue | ||
} | ||
// * develop のようなカレントブランチは対象外 | ||
if strings.HasPrefix(branch, "*") { | ||
continue | ||
} | ||
// master/developは対象外 | ||
if strings.Contains(branch, "master") || strings.Contains(branch, "develop") { | ||
continue | ||
} | ||
|
||
branches = append(branches, branch) | ||
} | ||
return branches, nil | ||
} | ||
|
||
func delBranch(name string) error { | ||
return exec.Command("git", "branch", "-d", name).Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/urfave/cli" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "git-rm-merged" | ||
app.Description = "The git sub command that removes the merged local branches." | ||
app.Action = func(c *cli.Context) error { | ||
fmt.Println("git-rm-merged!") | ||
return nil | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
app := cli.NewApp() | ||
app.Name = "git-rm-merged" | ||
app.Version = "1.0.0" | ||
app.Description = "The git sub command that removes the merged local branches." | ||
app.Action = mainAction | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func mainAction(c *cli.Context) error { | ||
branches, err := getMergedBranches() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, b := range branches { | ||
fmt.Printf("%s [y/n]:", b) | ||
|
||
var key string | ||
|
||
fmt.Scanln(&key) | ||
if (key != "y") { | ||
continue | ||
} | ||
|
||
err := delBranch(b) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |