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

add git checkout example + housekeeping #331

Merged
merged 2 commits into from
Apr 6, 2017

Conversation

marwan-at-work
Copy link
Contributor

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.

@@ -6,13 +6,16 @@ import (
"strings"
)

// CheckArgs should be uesed to esnure the right command line arguments are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/uesed/used/

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/naiivly/naively/

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)
Copy link
Contributor

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")
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link

codecov bot commented Apr 6, 2017

Codecov Report

Merging #331 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #331   +/-   ##
=======================================
  Coverage   77.36%   77.36%           
=======================================
  Files         117      117           
  Lines        8019     8019           
=======================================
  Hits         6204     6204           
  Misses       1156     1156           
  Partials      659      659
Impacted Files Coverage Δ
_examples/common.go 23.07% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ede779...e0b296d. Read the comment docs.

@mcuadros mcuadros merged commit c34356d into src-d:master Apr 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants