| 1 | package commandscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/ |
| 2 | |
| 3 | import ( |
| 4 | "os/execscip-go gomod github.com/golang/go/src go1.16 `os/exec`/" |
| 5 | |
| 6 | "github.com/isacikgoz/gitbatch/internal/gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/" |
| 7 | ) |
| 8 | |
| 9 | // CheckoutOptions defines the rules of checkout command |
| 10 | type CheckoutOptionsscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions# struct { |
| 11 | TargetRefscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#TargetRef. string |
| 12 | CreateIfAbsentscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#CreateIfAbsent. bool |
| 13 | CommandModescip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#CommandMode. Modescip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/Mode# |
| 14 | } |
| 15 | |
| 16 | // Checkout is a wrapper function for "git checkout" command. |
| 17 | func Checkoutscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/Checkout().(r *gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Repositoryscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#, o *CheckoutOptionsscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#) error { |
| 18 | var branch *gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Branchscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Branch# |
| 19 | for _, b := range r.Branchesscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#Branches. { |
| 20 | if b.Namescip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Branch#Name. == o.TargetRefscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#TargetRef. { |
| 21 | branch = b |
| 22 | break |
| 23 | } |
| 24 | } |
| 25 | msg := "checkout in progress" |
| 26 | if branch != nil { |
| 27 | if err := r.Checkoutscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#Checkout().(branch); err != nil { |
| 28 | r.SetWorkStatusscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#SetWorkStatus().(gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Failscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Fail.) |
| 29 | msg = err.Error() |
| 30 | } else { |
| 31 | r.SetWorkStatusscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#SetWorkStatus().(gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Successscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Success.) |
| 32 | msg = "switched to " + o.TargetRefscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#TargetRef. |
| 33 | } |
| 34 | } else if o.CreateIfAbsentscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#CreateIfAbsent. { |
| 35 | args := []string{"checkout", "-b", o.TargetRefscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#TargetRef.} |
| 36 | cmd := execscip-go gomod github.com/golang/go/src go1.16 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.16 `os/exec`/Command().("git", args...) |
| 37 | cmd.Dirscip-go gomod github.com/golang/go/src go1.16 `os/exec`/Cmd#Dir. = r.AbsPathscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#AbsPath. |
| 38 | _, err := cmd.CombinedOutputscip-go gomod github.com/golang/go/src go1.16 `os/exec`/Cmd#CombinedOutput().() |
| 39 | if err != nil { |
| 40 | r.SetWorkStatusscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#SetWorkStatus().(gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Failscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Fail.) |
| 41 | msg = err.Error() |
| 42 | } else { |
| 43 | r.SetWorkStatusscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#SetWorkStatus().(gitscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/.Successscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Success.) |
| 44 | msg = "switched to " + o.TargetRefscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/command`/CheckoutOptions#TargetRef. |
| 45 | } |
| 46 | } |
| 47 | r.Statescip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#State..Messagescip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/RepositoryState#Message. = msg |
| 48 | return r.Refreshscip-go gomod github.com/isacikgoz/gitbatch . `github.com/isacikgoz/gitbatch/internal/git`/Repository#Refresh().() |
| 49 | } |