Skip to content

Commit 4706e15

Browse files
Fix bugs in handling Git
- ignore errors when a symlink cannot be open - it's not uncommon for Git repos to contain symlinks that are intentionally broken, e.g. in case one is pointing to a file that a user is meant to install - handle top-level dir properly - previously the code was checking parent dir first and foremost, skipping the case when the top-level dir is the starting point
1 parent 1f9ef7b commit 4706e15

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

attest/vcs/git/git.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ func (c *PathChecker) Check() (bool, bool, error) {
377377
}
378378
unmodified, _, err := isBlobUnmodified(worktree, &f.Blob, filepath.Join(repoPath, f.Name))
379379
if err != nil {
380+
if f.Mode == filemode.Symlink {
381+
// TODO: should at least log a warning for broken symlink
382+
return nil
383+
}
380384
return err
381385
}
382386
if !unmodified {
@@ -508,6 +512,9 @@ func findByPath(repo *gogit.Repository, path string) (object.Object, error) {
508512
if err != nil {
509513
return nil, err
510514
}
515+
if path == "." {
516+
return tree, nil
517+
}
511518
treeEntry, err := tree.FindEntry(path)
512519
switch err {
513520
case nil:
@@ -527,12 +534,12 @@ func findByPath(repo *gogit.Repository, path string) (object.Object, error) {
527534
}
528535

529536
func detectRepo(path string) (*gogit.Repository, bool) {
537+
if repo, err := gogit.PlainOpen(path); err == nil {
538+
return repo, true
539+
}
530540
dir := filepath.Dir(path)
531541
if dir == path { // reached root
532542
return nil, false
533543
}
534-
if repo, err := gogit.PlainOpen(dir); err == nil {
535-
return repo, true
536-
}
537544
return detectRepo(dir)
538545
}

0 commit comments

Comments
 (0)