Skip to content

Commit 532729d

Browse files
authored
Don't delete branch twice (#55)
1 parent e9c1834 commit 532729d

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

internal/cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func (a App) Command() *cobra.Command {
2323
}
2424
cmd.SetOut(os.Stdout)
2525
cmd.SetErr(os.Stderr)
26+
cmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) {
27+
cmd.SilenceUsage = true
28+
}
2629
opts := &cli.Options{}
2730
subs := []subcommand{
2831
sync{opts},

internal/cmd/sync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type sync struct {
1515

1616
func (s sync) command() *cobra.Command {
1717
cmd := &cobra.Command{
18-
Use: "sync",
18+
Use: "sync [project-dir]",
1919
Short: "Synchronize to the upstream releases",
2020
ValidArgs: []string{"REPOSITORY"},
21-
Args: cobra.OnlyValidArgs,
21+
Args: cobra.MaximumNArgs(1),
2222
RunE: s.run,
2323
}
2424
return cmd
@@ -35,16 +35,16 @@ func (s sync) project(args []string) func() config.Project {
3535
if err != nil {
3636
wd = "/"
3737
}
38+
if len(args) > 0 {
39+
wd = args[0]
40+
}
3841
if !path.IsAbs(configPath) {
3942
configPath = path.Join(wd, configPath)
4043
}
4144
project := config.Project{
4245
ConfigPath: configPath,
4346
Path: wd,
4447
}
45-
if len(args) > 0 {
46-
project.Path = args[0]
47-
}
4848
return project
4949
}
5050
}

pkg/sync/create_pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c createPR) open() error {
101101
cl := github.NewClient(args...)
102102
cl.ProjectDir = c.Path
103103
buff, err := cl.Execute(c.Context)
104-
defer c.Println("Github client:", buff)
104+
defer c.Println("Github client:", string(buff))
105105
return errors.Wrap(err, ErrSyncFailed)
106106
}
107107

pkg/sync/mirror_release.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ func (r createNewRelease) checkoutAsNewRelease(upstreamBranch, downstreamBranch
7474

7575
type push struct {
7676
state.State
77-
branch string
77+
branch string
78+
skipDelete bool
7879
}
7980

8081
func (p push) steps() []step {
81-
return []step{
82-
p.push,
83-
p.delete,
82+
st := []step{p.push}
83+
if !p.skipDelete {
84+
st = append(st, p.delete)
8485
}
86+
return st
8587
}
8688

8789
func (p push) push() error {

pkg/sync/resync_releases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (r resyncRelease) run() error {
8888
return nil
8989
}
9090
err = multiStep{
91-
r.pushBranch(syncBranch),
91+
r.pushBranch(syncBranch, skipDeleteOnPush),
9292
r.createSyncReleasePR(downstreamBranch, upstreamBranch, syncBranch),
9393
}.runSteps()
9494
return

pkg/sync/sync_release_next.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ func (o Operation) syncReleaseNext() error {
99
})
1010
}
1111

12-
func (o Operation) pushBranch(branch string) step {
12+
type pushOpt func(*push)
13+
14+
func skipDeleteOnPush(p *push) {
15+
p.skipDelete = true
16+
}
17+
18+
func (o Operation) pushBranch(branch string, opts ...pushOpt) step {
1319
return func() error {
1420
p := push{
1521
State: o.State,
1622
branch: branch,
1723
}
24+
for _, opt := range opts {
25+
opt(&p)
26+
}
1827
return runSteps(p.steps())
1928
}
2029
}

0 commit comments

Comments
 (0)