Skip to content

Commit 061e80a

Browse files
committed
[SumDBVerify] Check for git ownership
Under the hood this uses 2 different git implementations: 1) go-git, 2) system git. The go-git usage was fine with slightly unusual ownership rules, but system git (invoked by x/mod/zip) complained. This adds a small amount of error processing to catch the specific error reported. This fixes #69.
1 parent d76a0d4 commit 061e80a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎vindex/cmd/sumdbverify/client.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"net/http"
2929
"net/url"
3030
"os"
31+
"os/exec"
3132
"path/filepath"
3233
"regexp"
3334
"strconv"
@@ -380,6 +381,9 @@ func reportVersion(ctx context.Context, modRoot string, goModPath string, modNam
380381
subdir = ""
381382
}
382383
if err := zip.CreateFromVCS(f, modVer, modRoot, hash.String(), subdir); err != nil {
384+
if diagErr := diagnoseGitError(modRoot); diagErr != nil {
385+
return report, fmt.Errorf("failed to create zip file: %v (diagnostics: %v)", err, diagErr)
386+
}
383387
return report, fmt.Errorf("failed to create zip file: %v", err)
384388
}
385389
report.gitZipHash, err = dirhash.HashZip(f.Name(), dirhash.Hash1)
@@ -508,3 +512,20 @@ func newInputLogClientFromFlags() *client.InputLogClient {
508512
}
509513
return c
510514
}
515+
516+
// diagnoseGitError checks if the git command fails due to ownership issues
517+
// and returns a helpful error if so.
518+
func diagnoseGitError(dir string) error {
519+
cmd := exec.Command("git", "rev-parse", "--git-dir")
520+
cmd.Dir = dir
521+
var stderr bytes.Buffer
522+
cmd.Stderr = &stderr
523+
if err := cmd.Run(); err != nil {
524+
stderrStr := stderr.String()
525+
if strings.Contains(stderrStr, "detected dubious ownership") {
526+
return errors.New(strings.TrimSpace(stderrStr))
527+
}
528+
}
529+
return nil
530+
}
531+

0 commit comments

Comments
 (0)