Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
jolheiser | 8027ad224b | |
jolheiser | fd9f898315 | |
jolheiser | 50d40aacc1 | |
jolheiser | f335f5805f | |
jolheiser | 190ea6c7f3 | |
jolheiser | fe0e2e5707 |
112
DOCS.md
112
DOCS.md
|
@ -6,12 +6,14 @@ git-ea is the base command
|
||||||
git-ea
|
git-ea
|
||||||
├─ backport
|
├─ backport
|
||||||
├─ branch
|
├─ branch
|
||||||
|
├─ cd
|
||||||
├─ cleanup
|
├─ cleanup
|
||||||
├─ frontport
|
├─ frontport
|
||||||
├─ ide
|
├─ ide
|
||||||
├─ init
|
├─ init
|
||||||
├─ post
|
├─ post
|
||||||
└─ pr
|
├─ pr
|
||||||
|
└─ tag
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,25 +33,6 @@ git-ea <cmd>
|
||||||
**--version,-v**: Print git-ea version
|
**--version,-v**: Print git-ea version
|
||||||
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
## cleanup
|
|
||||||
|
|
||||||
cleanup removes named branches, or interactive if no arguments
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
[--help]
|
|
||||||
```
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```
|
|
||||||
cleanup [branches...]
|
|
||||||
```
|
|
||||||
|
|
||||||
**--help**: Show help
|
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
## backport
|
## backport
|
||||||
|
@ -61,6 +44,7 @@ backport cherry-picks a commit and applies it to a clean branch based on `releas
|
||||||
[--from,-f]=[value]
|
[--from,-f]=[value]
|
||||||
[--help]
|
[--help]
|
||||||
[--list,-l]
|
[--list,-l]
|
||||||
|
[--push,-p]
|
||||||
[--to,-t]=[value]
|
[--to,-t]=[value]
|
||||||
```
|
```
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
@ -78,6 +62,9 @@ backport --from [release=main] --to [release=latest]
|
||||||
**--list,-l**: Open repository to see needed backports
|
**--list,-l**: Open repository to see needed backports
|
||||||
|
|
||||||
|
|
||||||
|
**--push,-p**: Push immediately
|
||||||
|
|
||||||
|
|
||||||
**--to,-t**="": Release to backport to (ex: `17`, default: `latest`)
|
**--to,-t**="": Release to backport to (ex: `17`, default: `latest`)
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,7 +80,7 @@ branch creates a new branch called `name` based on `base`
|
||||||
[--help]
|
[--help]
|
||||||
[--ide,-i]
|
[--ide,-i]
|
||||||
[--list,-l]
|
[--list,-l]
|
||||||
[--no-fetch,-nf]
|
[--no-fetch,-n]
|
||||||
```
|
```
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
|
||||||
|
@ -113,7 +100,57 @@ branch --base [ref=main] <name>
|
||||||
**--list,-l**: List branches available
|
**--list,-l**: List branches available
|
||||||
|
|
||||||
|
|
||||||
**--no-fetch,-nf**: Skip fetching
|
**--no-fetch,-n**: Skip fetching
|
||||||
|
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
## cleanup
|
||||||
|
|
||||||
|
cleanup removes named branches, or interactive if no arguments
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
[--force,-f]
|
||||||
|
[--help]
|
||||||
|
[--prune,-p]
|
||||||
|
```
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```
|
||||||
|
cleanup [branches...]
|
||||||
|
```
|
||||||
|
|
||||||
|
**--force,-f**: Force cleanup
|
||||||
|
|
||||||
|
|
||||||
|
**--help**: Show help
|
||||||
|
|
||||||
|
|
||||||
|
**--prune,-p**: Prune worktrees
|
||||||
|
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
## cd
|
||||||
|
|
||||||
|
Open a shell in the specified `workspace`
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
[--help]
|
||||||
|
[--print,-p]
|
||||||
|
```
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd [workspace=base]
|
||||||
|
```
|
||||||
|
|
||||||
|
**--help**: Show help
|
||||||
|
|
||||||
|
|
||||||
|
**--print,-p**: Print workspace dir instead of spawning a shell
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
@ -126,6 +163,7 @@ frontport cherry-picks a commit and applies it to a clean branch based on `relea
|
||||||
```
|
```
|
||||||
[--from,-f]=[value]
|
[--from,-f]=[value]
|
||||||
[--help]
|
[--help]
|
||||||
|
[--push,-p]
|
||||||
[--to,-t]=[value]
|
[--to,-t]=[value]
|
||||||
```
|
```
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
@ -140,6 +178,9 @@ frontport --from [release=latest] --to [release=main]
|
||||||
**--help**: Show help
|
**--help**: Show help
|
||||||
|
|
||||||
|
|
||||||
|
**--push,-p**: Push immediately
|
||||||
|
|
||||||
|
|
||||||
**--to,-t**="": Release to frontport to (ex: `main`, default: `main`)
|
**--to,-t**="": Release to frontport to (ex: `main`, default: `main`)
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,6 +192,7 @@ ide starts an IDE for `branch`
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
[--gui,-g]
|
||||||
[--help]
|
[--help]
|
||||||
```
|
```
|
||||||
**Usage**:
|
**Usage**:
|
||||||
|
@ -159,6 +201,9 @@ ide starts an IDE for `branch`
|
||||||
ide <branch>
|
ide <branch>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**--gui,-g**: Prefer GUI editor
|
||||||
|
|
||||||
|
|
||||||
**--help**: Show help
|
**--help**: Show help
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,3 +286,26 @@ pr <index>
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
## tag
|
||||||
|
|
||||||
|
tag makes a signed tag for `branch`
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
[--help]
|
||||||
|
[--push,-p]
|
||||||
|
```
|
||||||
|
**Usage**:
|
||||||
|
|
||||||
|
```
|
||||||
|
tag <branch>
|
||||||
|
```
|
||||||
|
|
||||||
|
**--help**: Show help
|
||||||
|
|
||||||
|
|
||||||
|
**--push,-p**: Push immediately
|
||||||
|
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ func (h *Handler) Backport() *ffcli.Command {
|
||||||
fs.StringVar(toFlag, "t", *toFlag, "--to")
|
fs.StringVar(toFlag, "t", *toFlag, "--to")
|
||||||
listFlag := fs.Bool("list", false, "Open repository to see needed backports")
|
listFlag := fs.Bool("list", false, "Open repository to see needed backports")
|
||||||
fs.BoolVar(listFlag, "l", *listFlag, "--list")
|
fs.BoolVar(listFlag, "l", *listFlag, "--list")
|
||||||
|
pushFlag := fs.Bool("push", false, "Push immediately")
|
||||||
|
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
|
||||||
return &ffcli.Command{
|
return &ffcli.Command{
|
||||||
Name: "backport",
|
Name: "backport",
|
||||||
FlagSet: fs,
|
FlagSet: fs,
|
||||||
|
@ -85,13 +87,21 @@ func (h *Handler) Backport() *ffcli.Command {
|
||||||
index = m[1]
|
index = m[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
branch := fmt.Sprintf("backport-%s", index)
|
branch := fmt.Sprintf("backport-%s-%s", to, index)
|
||||||
base := fmt.Sprintf("upstream/release/v1.%s", to)
|
base := fmt.Sprintf("upstream/release/v1.%s", to)
|
||||||
if err := h.Branch().ParseAndRun(ctx, []string{"--base", base, branch}); err != nil {
|
if err := h.Branch().ParseAndRun(ctx, []string{"--base", base, branch}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp])
|
if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if *pushFlag {
|
||||||
|
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func (h *Handler) Branch() *ffcli.Command {
|
func (h *Handler) Branch() *ffcli.Command {
|
||||||
fs := flag.NewFlagSet("branch", flag.ContinueOnError)
|
fs := flag.NewFlagSet("branch", flag.ContinueOnError)
|
||||||
noFetchFlag := fs.Bool("no-fetch", false, "Skip fetching")
|
noFetchFlag := fs.Bool("no-fetch", false, "Skip fetching")
|
||||||
fs.BoolVar(noFetchFlag, "nf", *noFetchFlag, "--no-fetch")
|
fs.BoolVar(noFetchFlag, "n", *noFetchFlag, "--no-fetch")
|
||||||
baseFlag := fs.String("base", "main", "Ref to base from")
|
baseFlag := fs.String("base", "main", "Ref to base from")
|
||||||
fs.StringVar(baseFlag, "b", *baseFlag, "--base")
|
fs.StringVar(baseFlag, "b", *baseFlag, "--base")
|
||||||
listFlag := fs.Bool("list", false, "List branches available")
|
listFlag := fs.Bool("list", false, "List branches available")
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"go.jolheiser.com/git-ea/config"
|
||||||
|
|
||||||
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *Handler) CD() *ffcli.Command {
|
||||||
|
fs := flag.NewFlagSet("cd", flag.ContinueOnError)
|
||||||
|
printFlag := fs.Bool("print", false, "Print workspace dir instead of spawning a shell")
|
||||||
|
fs.BoolVar(printFlag, "p", *printFlag, "--print")
|
||||||
|
return &ffcli.Command{
|
||||||
|
Name: "cd",
|
||||||
|
FlagSet: fs,
|
||||||
|
ShortUsage: "cd [workspace=base]",
|
||||||
|
ShortHelp: "Open a shell in the specified `workspace`",
|
||||||
|
Exec: func(ctx context.Context, _ []string) error {
|
||||||
|
dir := h.Config.Workspace()
|
||||||
|
if fs.NArg() > 0 {
|
||||||
|
dir = h.Config.WorkspaceBranch(fs.Arg(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
if *printFlag {
|
||||||
|
fmt.Println(dir)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
command, args := cd(h.Config)
|
||||||
|
cmd := exec.CommandContext(ctx, command, args...)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = dir
|
||||||
|
return cmd.Run()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cd(cfg *config.Config) (string, []string) {
|
||||||
|
if cfg.CD.Command != "" {
|
||||||
|
return cfg.CD.Command, cfg.CD.Args
|
||||||
|
}
|
||||||
|
var shell string
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
shell = "powershell.exe"
|
||||||
|
case "linux":
|
||||||
|
shell = "/bin/bash"
|
||||||
|
}
|
||||||
|
return shell, nil
|
||||||
|
}
|
|
@ -11,6 +11,10 @@ import (
|
||||||
|
|
||||||
func (h *Handler) Cleanup() *ffcli.Command {
|
func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
fs := flag.NewFlagSet("cleanup", flag.ContinueOnError)
|
fs := flag.NewFlagSet("cleanup", flag.ContinueOnError)
|
||||||
|
forceFlag := fs.Bool("force", false, "Force cleanup")
|
||||||
|
fs.BoolVar(forceFlag, "f", *forceFlag, "--force")
|
||||||
|
pruneFlag := fs.Bool("prune", false, "Prune worktrees")
|
||||||
|
fs.BoolVar(pruneFlag, "p", *pruneFlag, "--prune")
|
||||||
return &ffcli.Command{
|
return &ffcli.Command{
|
||||||
Name: "cleanup",
|
Name: "cleanup",
|
||||||
FlagSet: fs,
|
FlagSet: fs,
|
||||||
|
@ -21,9 +25,13 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *pruneFlag {
|
||||||
|
return run(ctx, h.Config.Workspace(), "git", "worktree", "prune")
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if err := removeWorktree(h, ctx, arg); err != nil {
|
if err := removeWorktree(h, ctx, arg, *forceFlag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +56,7 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rm := range remove {
|
for _, rm := range remove {
|
||||||
if err := removeWorktree(h, ctx, rm); err != nil {
|
if err := removeWorktree(h, ctx, rm, *forceFlag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +66,13 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeWorktree(h *Handler, ctx context.Context, name string) error {
|
func removeWorktree(h *Handler, ctx context.Context, name string, force bool) error {
|
||||||
if err := h.run(ctx, "git", "worktree", "remove", name); err != nil {
|
args := []string{"worktree", "remove"}
|
||||||
|
if force {
|
||||||
|
args = append(args, "--force")
|
||||||
|
}
|
||||||
|
args = append(args, name)
|
||||||
|
if err := h.run(ctx, "git", args...); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return h.run(ctx, "git", "branch", "-D", name)
|
return h.run(ctx, "git", "branch", "-D", name)
|
||||||
|
|
15
cmd/cmd.go
15
cmd/cmd.go
|
@ -45,14 +45,16 @@ func New() (*ffcli.Command, error) {
|
||||||
ShortUsage: "git-ea <cmd>",
|
ShortUsage: "git-ea <cmd>",
|
||||||
ShortHelp: "git-ea is the base command",
|
ShortHelp: "git-ea is the base command",
|
||||||
Subcommands: []*ffcli.Command{
|
Subcommands: []*ffcli.Command{
|
||||||
handler.Cleanup(),
|
|
||||||
handler.Backport(),
|
handler.Backport(),
|
||||||
handler.Branch(),
|
handler.Branch(),
|
||||||
|
handler.Cleanup(),
|
||||||
|
handler.CD(),
|
||||||
handler.Frontport(),
|
handler.Frontport(),
|
||||||
handler.IDE(),
|
handler.IDE(),
|
||||||
handler.Init(),
|
handler.Init(),
|
||||||
handler.Post(),
|
handler.Post(),
|
||||||
handler.PR(),
|
handler.PR(),
|
||||||
|
handler.Tag(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.Exec = func(_ context.Context, _ []string) error {
|
c.Exec = func(_ context.Context, _ []string) error {
|
||||||
|
@ -61,16 +63,7 @@ func New() (*ffcli.Command, error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := cfg.Base
|
fmt.Println(ffcli.DefaultUsageFunc(c))
|
||||||
if fs.NArg() > 0 {
|
|
||||||
if strings.EqualFold(fs.Arg(0), "help") {
|
|
||||||
fmt.Println(ffcli.DefaultUsageFunc(c))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
dir = cfg.WorkspaceBranch(fs.Arg(0))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(dir)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
|
|
|
@ -18,6 +18,8 @@ func (h *Handler) Frontport() *ffcli.Command {
|
||||||
fs.StringVar(fromFlag, "f", *fromFlag, "--from")
|
fs.StringVar(fromFlag, "f", *fromFlag, "--from")
|
||||||
toFlag := fs.String("to", "", "Release to frontport to (ex: `main`, default: `main`)")
|
toFlag := fs.String("to", "", "Release to frontport to (ex: `main`, default: `main`)")
|
||||||
fs.StringVar(toFlag, "t", *toFlag, "--to")
|
fs.StringVar(toFlag, "t", *toFlag, "--to")
|
||||||
|
pushFlag := fs.Bool("push", false, "Push immediately")
|
||||||
|
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
|
||||||
return &ffcli.Command{
|
return &ffcli.Command{
|
||||||
Name: "frontport",
|
Name: "frontport",
|
||||||
FlagSet: fs,
|
FlagSet: fs,
|
||||||
|
@ -70,7 +72,7 @@ func (h *Handler) Frontport() *ffcli.Command {
|
||||||
index = m[1]
|
index = m[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
branch := fmt.Sprintf("frontport-%s", index)
|
branch := fmt.Sprintf("frontport-%s-%s", from, index)
|
||||||
|
|
||||||
base := *toFlag
|
base := *toFlag
|
||||||
if base == "" {
|
if base == "" {
|
||||||
|
@ -83,7 +85,15 @@ func (h *Handler) Frontport() *ffcli.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp])
|
if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if *pushFlag {
|
||||||
|
return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
cmd/ide.go
27
cmd/ide.go
|
@ -3,14 +3,17 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
|
||||||
"github.com/peterbourgon/ff/v3/ffcli"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) IDE() *ffcli.Command {
|
func (h *Handler) IDE() *ffcli.Command {
|
||||||
fs := flag.NewFlagSet("ide", flag.ContinueOnError)
|
fs := flag.NewFlagSet("ide", flag.ContinueOnError)
|
||||||
|
guiFlag := fs.Bool("gui", false, "Prefer GUI editor")
|
||||||
|
fs.BoolVar(guiFlag, "g", *guiFlag, "--gui")
|
||||||
return &ffcli.Command{
|
return &ffcli.Command{
|
||||||
Name: "ide",
|
Name: "ide",
|
||||||
FlagSet: fs,
|
FlagSet: fs,
|
||||||
|
@ -38,7 +41,7 @@ func (h *Handler) IDE() *ffcli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := h.Config.WorkspaceBranch(branch)
|
path := h.Config.WorkspaceBranch(branch)
|
||||||
cmd := exec.Command(getIDE(), path)
|
cmd := exec.Command(getIDE(*guiFlag), path)
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
@ -48,13 +51,25 @@ func (h *Handler) IDE() *ffcli.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIDE() string {
|
func getIDE(preferGUI bool) string {
|
||||||
for _, ide := range []string{
|
term := []string{
|
||||||
"hx",
|
"hx",
|
||||||
"nvim",
|
"nvim",
|
||||||
|
}
|
||||||
|
gui := []string{
|
||||||
|
"lapce",
|
||||||
"goland",
|
"goland",
|
||||||
|
}
|
||||||
|
def := []string{
|
||||||
"vi",
|
"vi",
|
||||||
} {
|
}
|
||||||
|
|
||||||
|
ides := append(term, gui...)
|
||||||
|
if preferGUI {
|
||||||
|
ides = append(gui, term...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ide := range append(ides, def...) {
|
||||||
if i, err := exec.LookPath(ide); err == nil {
|
if i, err := exec.LookPath(ide); err == nil {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"github.com/go-git/go-git/v5"
|
||||||
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
treeURL = "https://github.com/go-gitea/gitea/tree/%s"
|
||||||
|
versionRe = regexp.MustCompile(`v\d+\.\d+\.\d+`)
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *Handler) Tag() *ffcli.Command {
|
||||||
|
fs := flag.NewFlagSet("tag", flag.ContinueOnError)
|
||||||
|
pushFlag := fs.Bool("push", false, "Push immediately")
|
||||||
|
fs.BoolVar(pushFlag, "p", *pushFlag, "--push")
|
||||||
|
return &ffcli.Command{
|
||||||
|
Name: "tag",
|
||||||
|
FlagSet: fs,
|
||||||
|
ShortUsage: "tag <branch>",
|
||||||
|
ShortHelp: "tag makes a signed tag for `branch`",
|
||||||
|
Exec: func(ctx context.Context, args []string) error {
|
||||||
|
if err := h.checkInit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.fetch(ctx)
|
||||||
|
|
||||||
|
var branch string
|
||||||
|
if len(args) > 0 {
|
||||||
|
branch = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if branch == "" {
|
||||||
|
var branches []string
|
||||||
|
remote, err := h.repo().Remote("upstream")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
refs, err := remote.List(&git.ListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, ref := range refs {
|
||||||
|
if ref.Name().IsBranch() {
|
||||||
|
branches = append(branches, strings.TrimPrefix(ref.Name().String(), "refs/heads/"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(branches)
|
||||||
|
if err := survey.AskOne(&survey.Select{
|
||||||
|
Message: "Branch",
|
||||||
|
Options: branches,
|
||||||
|
}, &branch, survey.WithValidator(survey.Required)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(branch, "release") {
|
||||||
|
if !strings.HasPrefix(branch, "v") {
|
||||||
|
branch = fmt.Sprintf("v%s", branch)
|
||||||
|
}
|
||||||
|
branch = fmt.Sprintf("release/%s", branch)
|
||||||
|
}
|
||||||
|
|
||||||
|
var version string
|
||||||
|
if err := survey.AskOne(&survey.Input{
|
||||||
|
Message: "Version",
|
||||||
|
}, &version, survey.WithValidator(func(ans any) error {
|
||||||
|
if !versionRe.MatchString(fmt.Sprint(ans)) {
|
||||||
|
return errors.New("version isn't valid v$maj.$min.$")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
workspaceName := fmt.Sprintf("release-%s", version)
|
||||||
|
if err := h.Branch().ParseAndRun(ctx, []string{"--base", branch, workspaceName}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var changelog string
|
||||||
|
if err := survey.AskOne(&survey.Editor{
|
||||||
|
Message: "Changelog",
|
||||||
|
FileName: "*.md",
|
||||||
|
}, &changelog, survey.WithValidator(survey.Required)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Create(filepath.Join(h.Config.WorkspaceBranch(workspaceName), "release.notes"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := fi.WriteString(changelog); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := fi.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if *pushFlag {
|
||||||
|
return run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "push", "upstream", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("cd %s && git push upstream %s \n", h.Config.WorkspaceBranch(workspaceName), version)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,8 +8,14 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CD struct {
|
||||||
|
Command string `json:"command"`
|
||||||
|
Args []string `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Base string `json:"base"`
|
Base string `json:"base"`
|
||||||
|
CD CD `json:"cd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Workspace() string {
|
func (c *Config) Workspace() string {
|
||||||
|
@ -40,9 +46,13 @@ func (c *Config) Branches() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func path() (string, error) {
|
func path() (string, error) {
|
||||||
userCfgDir, err := os.UserConfigDir()
|
userCfgDir, ok := os.LookupEnv("XDG_CONFIG_HOME")
|
||||||
if err != nil {
|
if !ok {
|
||||||
return "", err
|
var err error
|
||||||
|
userCfgDir, err = os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cfgDir := filepath.Join(userCfgDir, "git-ea")
|
cfgDir := filepath.Join(userCfgDir, "git-ea")
|
||||||
return filepath.Join(cfgDir, "config.json"), os.MkdirAll(cfgDir, os.ModePerm)
|
return filepath.Join(cfgDir, "config.json"), os.MkdirAll(cfgDir, os.ModePerm)
|
||||||
|
@ -63,7 +73,7 @@ func Load() (*Config, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := fi.WriteString("{}"); err != nil {
|
if _, err := fi.WriteString(`{}`); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := fi.Seek(0, 0); err != nil {
|
if _, err := fi.Seek(0, 0); err != nil {
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
def "nu-complete git-ea branches" [] {
|
||||||
|
^git-ea branch -l | lines | each { |line| $line | str trim }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Backport
|
||||||
|
export extern "git ea backport" [
|
||||||
|
--from(-f) # From branch
|
||||||
|
--list(-l) # Open a web browser to view needed backports
|
||||||
|
--push(-p) # Push immediately
|
||||||
|
--to(-t) # To branch
|
||||||
|
]
|
||||||
|
|
||||||
|
# Branch
|
||||||
|
export extern "git ea branch" [
|
||||||
|
name?: string # Branch name
|
||||||
|
--base(-b) # Branch base
|
||||||
|
--ide(-i) # Open an IDE for the new branch
|
||||||
|
--list(-l) # List branches
|
||||||
|
--no-fetch(-n) # Skip fetching
|
||||||
|
]
|
||||||
|
|
||||||
|
# CD
|
||||||
|
export extern "git ea cd" [
|
||||||
|
workspace?: string@"nu-complete git-ea branches" # Workspace
|
||||||
|
--print(-p) # Print instead of spawning shell
|
||||||
|
]
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
export extern "git ea cleanup" [
|
||||||
|
...branches: string # Branch names
|
||||||
|
--force(-f) # Force cleanup
|
||||||
|
--prune(-p) # Prune worktrees
|
||||||
|
]
|
||||||
|
|
||||||
|
# Frontport
|
||||||
|
export extern "git ea frontport" [
|
||||||
|
--from(-f) # From branch
|
||||||
|
--push(-p) # Push immediately
|
||||||
|
--to(-t) # To branch
|
||||||
|
]
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
export extern "git ea ide" [
|
||||||
|
workspace?: string@"nu-complete git-ea branches" # Workspace
|
||||||
|
--gui(-g) # Prefer GUI
|
||||||
|
]
|
||||||
|
|
||||||
|
# Init
|
||||||
|
export extern "git ea init" []
|
||||||
|
|
||||||
|
# Post
|
||||||
|
export extern "git ea post" [
|
||||||
|
--author(-a) # Author
|
||||||
|
--changelog(-c) # Changelog (no header)
|
||||||
|
--milestone(-m) # Milestone
|
||||||
|
--output(-o) # Output file (default: `content/post/release-of-${milestone}.md`)
|
||||||
|
]
|
||||||
|
|
||||||
|
# PR
|
||||||
|
export extern "git ea pr" [
|
||||||
|
index: int # PR index
|
||||||
|
--ide(-i) # Open IDE for this PR
|
||||||
|
]
|
||||||
|
|
||||||
|
# Tag
|
||||||
|
export extern "git ea tag" [
|
||||||
|
branch?: string # The branch to tag
|
||||||
|
--push(-p) # Push immediately
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue