Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created November 7, 2014 17:51
Show Gist options
  • Save adamhjk/5a475b8dd45971a4e814 to your computer and use it in GitHub Desktop.
Save adamhjk/5a475b8dd45971a4e814 to your computer and use it in GitHub Desktop.
func dot_git_dir(dir string) string {
git_dir := path.Join(dir, ".git")
_, dir_error := os.Stat(git_dir)
if dir_error != nil {
if git_dir == "/.git" {
log.Fatal("Cannot find a .git directory")
}
return dot_git_dir(path.Dir(dir))
} else {
return git_dir
}
}
@anisse
Copy link

anisse commented Nov 8, 2014

Idiomatic golang uses the early return pattern, which means you can eliminate the else part of your code. See:
https://golang.org/doc/effective_go.html#if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment