Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Commit b688260

Browse files
committed
Simplify checkout with ResolveRevision
1 parent f07a85d commit b688260

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

cmd/install.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,21 @@ func gitCheckout(name string, repo string, version string, directory string) {
152152
jww.INFO.Printf("[%s] Checking out %s from %s", name, version, repo)
153153

154154
r, err := git.PlainClone(directory, false, &git.CloneOptions{
155-
URL: repo,
156-
NoCheckout: true,
155+
URL: repo,
157156
})
158157
CheckIfError(err)
159158

159+
h, err := r.ResolveRevision(plumbing.Revision(version))
160+
if err != nil {
161+
h, err = r.ResolveRevision(plumbing.Revision("origin/" + version))
162+
}
163+
CheckIfError(err)
164+
160165
w, err := r.Worktree()
161166
CheckIfError(err)
162167

163-
// Try checkoing out commits, tags and branches
164168
err = w.Checkout(&git.CheckoutOptions{
165-
Hash: plumbing.NewHash(version),
169+
Hash: plumbing.NewHash(h.String()),
166170
})
167-
if err != nil {
168-
err = w.Checkout(&git.CheckoutOptions{
169-
Branch: plumbing.ReferenceName("refs/tags/" + version),
170-
})
171-
}
172-
if err != nil {
173-
err = w.Checkout(&git.CheckoutOptions{
174-
Branch: plumbing.ReferenceName("refs/heads/" + version),
175-
})
176-
}
177171
CheckIfError(err)
178172
}

0 commit comments

Comments
 (0)