Fail clearly when repo has no commits. (#109, #84)
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 74aebdd..a6d012e 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -132,6 +132,10 @@
if err != nil {
return err
}
+ err = checkForEmptyGitRepo(ctx, config.Path)
+ if err != nil {
+ return err
+ }
imgName, err := findOrBuildDockerImage(ctx, config.Path, gitRoot, config.Model, config.ModelURL, config.ModelAPIKey, config.ForceRebuild, config.Verbose)
if err != nil {
@@ -839,6 +843,17 @@
return res, nil
}
+func checkForEmptyGitRepo(ctx context.Context, path string) error {
+ cmd := exec.CommandContext(ctx, "git", "rev-parse", "-q", "--verify", "HEAD")
+ cmd.Dir = path
+ _, err := cmd.CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("sketch needs to run from within a git repo with at least one commit.\nRun: %s",
+ "git commit --allow-empty -m 'initial commit'")
+ }
+ return nil
+}
+
func findGitRoot(ctx context.Context, path string) (string, error) {
cmd := exec.CommandContext(ctx, "git", "rev-parse", "--git-common-dir")
cmd.Dir = path