Add initial-commit CLI flag for specifying git reference

This adds a new -initial-commit flag to the sketch CLI which allows specifying
a different git reference besides HEAD as the starting point. The flag is
incompatible with -unsafe mode and will show an error if both are used.

Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/cmd/sketch/main.go b/cmd/sketch/main.go
index 3809701..89c4725 100644
--- a/cmd/sketch/main.go
+++ b/cmd/sketch/main.go
@@ -51,6 +51,7 @@
 	workingDir := flag.String("C", "", "when set, change to this directory before running")
 	sshPort := flag.Int("ssh_port", 0, "the host port number that the container's ssh server will listen on, or a randomly chosen port if this value is 0")
 	forceRebuild := flag.Bool("force-rebuild-container", false, "rebuild Docker container")
+	initialCommit := flag.String("initial-commit", "HEAD", "the git commit reference to use as starting point (incompatible with -unsafe)")
 
 	// Flags geared towards sketch developers or sketch internals:
 	gitUsername := flag.String("git-username", "", "(internal) username for git commits")
@@ -66,6 +67,10 @@
 
 	flag.Parse()
 
+	if *unsafe && *initialCommit != "HEAD" {
+		return fmt.Errorf("cannot use -initial-commit with -unsafe, they are incompatible")
+	}
+
 	if *version {
 		bi, ok := debug.ReadBuildInfo()
 		if ok {
@@ -201,6 +206,7 @@
 			OutsideWorkingDir: cwd,
 			OneShot:           *oneShot,
 			Prompt:            *prompt,
+			InitialCommit:     *initialCommit,
 		}
 		if err := dockerimg.LaunchContainer(ctx, stdout, stderr, config); err != nil {
 			if *verbose {
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 3a0cc7e..a6be67b 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -82,6 +82,9 @@
 
 	// Initial prompt
 	Prompt string
+
+	// Initial commit to use as starting point
+	InitialCommit string
 }
 
 // LaunchContainer creates a docker container for a project, installs sketch and opens a connection to it.
@@ -157,8 +160,8 @@
 
 	// Get the current host git commit
 	var commit string
-	if out, err := combinedOutput(ctx, "git", "rev-parse", "HEAD"); err != nil {
-		return fmt.Errorf("git rev-parse HEAD: %w", err)
+	if out, err := combinedOutput(ctx, "git", "rev-parse", config.InitialCommit); err != nil {
+		return fmt.Errorf("git rev-parse %s: %w", config.InitialCommit, err)
 	} else {
 		commit = strings.TrimSpace(string(out))
 	}