Checkout will checkout the given hash to the worktreeFS. If an empty string is given, we checkout master.
(hash string)
| 110 | // Checkout will checkout the given hash to the worktreeFS. If an empty string |
| 111 | // is given, we checkout master. |
| 112 | func (r *Repository) Checkout(hash string) error { |
| 113 | opts := &git.CheckoutOptions{ |
| 114 | Force: true, |
| 115 | } |
| 116 | |
| 117 | if hash != "" { |
| 118 | opts.Hash = plumbing.NewHash(hash) |
| 119 | } |
| 120 | |
| 121 | err := r.Worktree.Checkout(opts) |
| 122 | |
| 123 | // It's fine to ignore ErrReferenceNotFound because that means this is a |
| 124 | // repo without any commits which doesn't matter for our use cases. |
| 125 | if err != nil && !errors.Is(err, plumbing.ErrReferenceNotFound) { |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | func ensureHooks(fs billy.Filesystem) error { |
| 133 | exe, err := os.Executable() |
no outgoing calls
no test coverage detected