@@ -37,21 +37,24 @@ func (t Trac) String() string {
37
37
}
38
38
39
39
type Cache struct {
40
- debugf func (fmt string , args ... interface {})
41
- repoDir string
42
- repo * git.Repository
43
- excludes map [plumbing.Hash ]bool
44
- tracs map [plumbing.Hash ]* Trac
40
+ debugf func (fmt string , args ... interface {})
41
+ repoDir string
42
+ repo * git.Repository
43
+ autoexclude bool
44
+ excludes map [plumbing.Hash ]bool
45
+ tracs map [plumbing.Hash ]* Trac
45
46
}
46
47
47
48
func NewCache (rdir string , r * git.Repository , excludes []string ,
49
+ autoexclude bool ,
48
50
debugf func (fmt string , args ... interface {})) * Cache {
49
51
c := Cache {
50
- debugf : debugf ,
51
- repoDir : rdir ,
52
- repo : r ,
53
- excludes : make (map [plumbing.Hash ]bool ),
54
- tracs : make (map [plumbing.Hash ]* Trac ),
52
+ debugf : debugf ,
53
+ repoDir : rdir ,
54
+ repo : r ,
55
+ autoexclude : autoexclude ,
56
+ excludes : make (map [plumbing.Hash ]bool ),
57
+ tracs : make (map [plumbing.Hash ]* Trac ),
55
58
}
56
59
for _ , x := range excludes {
57
60
hash := plumbing .NewHash (x )
@@ -77,6 +80,49 @@ func (c *Cache) String() string {
77
80
return strings .Join (out , "\n " )
78
81
}
79
82
83
+ func (c * Cache ) UpdateBranchRefs () error {
84
+ branchIter , err := c .repo .Branches ()
85
+ if err != nil {
86
+ return fmt .Errorf ("GetBranches: %v" , err )
87
+ }
88
+
89
+ var branches []* plumbing.Reference
90
+ var commits []* object.Commit
91
+ err = branchIter .ForEach (func (b * plumbing.Reference ) error {
92
+ name := string (b .Name ())
93
+ if strings .HasSuffix (name , ".trac" ) {
94
+ return nil
95
+ }
96
+ c .debugf ("Scanning branch: %v\n " , name )
97
+ commit , err := c .TracByRef (name )
98
+ if err != nil {
99
+ return err
100
+ } else {
101
+ branches = append (branches , b )
102
+ commits = append (commits , commit )
103
+ }
104
+ return nil
105
+ })
106
+ if err != nil {
107
+ return err
108
+ }
109
+
110
+ for i := range branches {
111
+ newname := string (branches [i ].Name ()) + ".trac"
112
+ hash := commits [i ].Hash
113
+ c .debugf ("Updating %.10v -> %v\n " , hash , newname )
114
+
115
+ refname := plumbing .ReferenceName (newname )
116
+ ref := plumbing .NewHashReference (refname , hash )
117
+ err = c .repo .Storer .SetReference (ref )
118
+ if err != nil {
119
+ return fmt .Errorf ("update %v: %v" , refname , err )
120
+ }
121
+ }
122
+
123
+ return nil
124
+ }
125
+
80
126
func (c * Cache ) TracByRef (refname string ) (* object.Commit , error ) {
81
127
h , err := c .repo .ResolveRevision (plumbing .Revision (refname ))
82
128
if err != nil {
@@ -326,6 +372,9 @@ func (c *Cache) tracTree(path string, tree *object.Tree) (*Trac, error) {
326
372
if err != nil {
327
373
err = c .tryFetchFromSubmodules (subpath , e .Hash )
328
374
if err != nil {
375
+ if c .autoexclude {
376
+ continue
377
+ }
329
378
return nil , fmt .Errorf ("%v (maybe fetch it manually?)" , err )
330
379
}
331
380
}
0 commit comments