Skip to content

Commit 8a8b062

Browse files
authored
Update main.go
1 parent 2a5c38c commit 8a8b062

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

main.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package main
22

33
import (
4-
"fmt"
54
"flag"
5+
"fmt"
66
"go/parser"
77
"go/token"
88
"os"
99
"path/filepath"
1010
"strings"
1111

1212
"github.com/go-git/go-billy/v5/memfs"
13-
git "github.com/go-git/go-git/v5"
13+
"github.com/go-git/go-git/v5"
1414
"github.com/go-git/go-git/v5/plumbing"
1515
"github.com/go-git/go-git/v5/plumbing/object"
1616
"github.com/go-git/go-git/v5/plumbing/transport"
@@ -31,8 +31,23 @@ var (
3131
)
3232

3333
func parseFromHash(repo *git.Repository, hash string) (*object.Tree, map[string]string) {
34-
commit, err := repo.CommitObject(plumbing.NewHash(hash))
35-
die(err)
34+
commit, _ := repo.CommitObject(plumbing.NewHash(hash))
35+
if commit == nil {
36+
iter, err := repo.CommitObjects()
37+
die(err)
38+
39+
for {
40+
var err error
41+
commit, err = iter.Next()
42+
die(err)
43+
if strings.HasPrefix(commit.Hash.String(), hash) {
44+
break
45+
}
46+
}
47+
}
48+
if commit == nil {
49+
die(fmt.Errorf("commit %s not found", hash))
50+
}
3651

3752
tree, err := commit.Tree()
3853
die(err)
@@ -109,11 +124,10 @@ func main() {
109124

110125
for _, file := range patches {
111126
from, to := file.Files()
112-
if from != nil {
127+
if from != nil && to != nil {
128+
rawChanges[from.Path()] = true
129+
} else if from != nil {
113130
rawChanges[from.Path()] = true
114-
}
115-
if to != nil {
116-
rawChanges[to.Path()] = true
117131
}
118132
}
119133

0 commit comments

Comments
 (0)