Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up error handling, abstract a validation, add a cmd desc phrase
- Loading branch information
1 parent
a3ffe40
commit c1295b9
Showing
4 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func validateDir(dir string) { | ||
if dir == "" { | ||
cwd, err := os.Getwd() | ||
handleError(err) | ||
dir = cwd | ||
} | ||
|
||
abs, err := filepath.Abs(filepath.Join(dir, ".git")) | ||
handleError(err) | ||
|
||
if _, err := os.Stat(abs); os.IsNotExist(err) { | ||
handleError(fmt.Errorf("%s is not a git repository", abs)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters