Checkout checks out a branch using the git command. If create is true, it creates the branch (using -B) at the given startPoint. go-git wipes out git-ignored changes during checkout so must use the git command.
(repoDir, branch string, force, create bool, startPoint string)
| 44 | // If create is true, it creates the branch (using -B) at the given startPoint. |
| 45 | // go-git wipes out git-ignored changes during checkout so must use the git command. |
| 46 | func Checkout(repoDir, branch string, force, create bool, startPoint string) error { |
| 47 | args := []string{"checkout"} |
| 48 | if force { |
| 49 | args = append(args, "--force") |
| 50 | } |
| 51 | if create { |
| 52 | args = append(args, "-B", branch) |
| 53 | if startPoint != "" { |
| 54 | args = append(args, startPoint) |
| 55 | } |
| 56 | } else { |
| 57 | args = append(args, branch) |
| 58 | } |
| 59 | _, err := Run(context.Background(), repoDir, args...) |
| 60 | if err != nil { |
| 61 | if strings.Contains(err.Error(), "did not match") { |
| 62 | return ErrRefNotFound |
| 63 | } |
| 64 | return err |
| 65 | } |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | // MergeWithStrategy merge a branch into the current branch using the specified strategy. |
| 70 | func MergeWithStrategy(path, branch, strategy string) error { |