-
Notifications
You must be signed in to change notification settings - Fork 534
add git checkout example + housekeeping #331
Conversation
_examples/common.go
Outdated
@@ -6,13 +6,16 @@ import ( | |||
"strings" | |||
) | |||
|
|||
// CheckArgs should be uesed to esnure the right command line arguments are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/uesed/used/
_examples/common.go
Outdated
func CheckArgs(arg ...string) { | ||
if len(os.Args) < len(arg)+1 { | ||
Warning("Usage: %s %s", os.Args[0], strings.Join(arg, " ")) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// CheckIfError should be used to naiivly panics if an error is not nil. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/naiivly/naively/
_examples/checkout/main.go
Outdated
url, directory, commitRef := os.Args[1], os.Args[2], os.Args[3] | ||
|
||
// Clone the given repository to the given directory | ||
Info("git clone %s %s --recursive", url, directory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do a --recursive? This makes the example more complex
|
||
CheckIfError(w.Checkout(plumbing.NewHash(commitRef))) | ||
|
||
fmt.Println("voila") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can print the HEAD commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcuadros, the problem as i stated in the pr description, is that the head commit will still be the old one, because go-git does not checkout the commit in a detached state. So you will actually still get the old HEAD commit, but the difference is that you will have the changes from the target-ref applied directly to your current branch . Therefore, printing the HEAD commit would be misleading. Let me know if there's a more proper way to do this. Thanks!
Codecov Report
@@ Coverage Diff @@
## master #331 +/- ##
=======================================
Coverage 77.36% 77.36%
=======================================
Files 117 117
Lines 8019 8019
=======================================
Hits 6204 6204
Misses 1156 1156
Partials 659 659
Continue to review full report at Codecov.
|
Added a
git checkout <ref>
examples.One thing that's a bit different from the CLI command, is that when you do
git checkout <ref>
in the git CLI, your repo gets checked out in a detached state. However, go-git keeps you in the same branch with the added difference. Not sure if that's a bug or a feature. Or maybe there's another way to do checkout that mimics the CLI results.