@@ -4,9 +4,11 @@ import (
44 "context"
55 "fmt"
66
7- "github.com/ShotaKitazawa/isucontinuous/pkg/localrepo"
87 "go.uber.org/zap"
98 "k8s.io/utils/exec"
9+
10+ myerrors "github.com/ShotaKitazawa/isucontinuous/pkg/errors"
11+ "github.com/ShotaKitazawa/isucontinuous/pkg/localrepo"
1012)
1113
1214type ConfigPush struct {
@@ -35,32 +37,31 @@ func runPush(
3537 logger .Info ("start push" )
3638 defer func () { logger .Info ("finish push" ) }()
3739 // Check currentBranch
38- var isFirstCommit = false
3940 currentBranch , err := repo .CurrentBranch (ctx )
4041 if err != nil {
4142 return err
4243 } else if currentBranch != conf .GitBranch {
43- isFirstCommit , err = repo .IsFirstCommit (ctx )
44- if err != nil {
45- return err
46- } else if isFirstCommit {
47- if currentBranch == "" {
48- currentBranch = "<detached>"
49- }
50- return fmt .Errorf (
51- "current branch name is %s. Please exec `sync` command first to checkout to %s." ,
52- currentBranch , conf .GitBranch ,
53- )
44+ if currentBranch == "" {
45+ currentBranch = "<detached>"
5446 }
47+ return fmt .Errorf (
48+ "current branch name is %s. Please exec `sync` command first to checkout to %s." ,
49+ currentBranch , conf .GitBranch ,
50+ )
5551 }
5652 // Fetch
5753 if err := repo .Fetch (ctx ); err != nil {
5854 return err
5955 }
6056 // Validate whether ${BRANCH} == remotes/origin/${BRANCH}
61- if ok , err := repo .DiffWithRemote (ctx ); err != nil && ! isFirstCommit {
62- return err
63- } else if ! ok && ! isFirstCommit {
57+ if ok , err := repo .DiffWithRemote (ctx ); err != nil {
58+ switch err .(type ) {
59+ case myerrors.GitBranchIsFirstCommit :
60+ // pass
61+ default :
62+ return err
63+ }
64+ } else if ! ok {
6465 return fmt .Errorf ("there are differences between %s and remotes/origin/%s" , conf .GitBranch , conf .GitBranch )
6566 }
6667 // Execute add, commit, and push
0 commit comments