@@ -11,6 +11,8 @@ import (
11
11
"regexp"
12
12
"strings"
13
13
14
+ "github.com/codegangsta/cli"
15
+
14
16
"github.com/docker-library/go-dockerlibrary/manifest"
15
17
"github.com/docker-library/go-dockerlibrary/pkg/execpipe"
16
18
@@ -234,12 +236,20 @@ func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (stri
234
236
//Progress: os.Stdout,
235
237
})
236
238
if err != nil {
237
- return "" , err
239
+ if fetchErr := fetchGitCommit (arch , entry , gitRemote .Config ().URLs [0 ], fetchString ); fetchErr != nil {
240
+ return "" , cli .NewMultiError (err , fetchErr )
241
+ }
238
242
}
239
243
240
244
commit , err := getGitCommit (entry .ArchGitCommit (arch ))
241
245
if err != nil {
242
- return "" , err
246
+ if fetchErr := fetchGitCommit (arch , entry , gitRemote .Config ().URLs [0 ], fetchString ); fetchErr != nil {
247
+ return "" , cli .NewMultiError (err , fetchErr )
248
+ }
249
+ commit , err = getGitCommit (entry .ArchGitCommit (arch ))
250
+ if err != nil {
251
+ return "" , err
252
+ }
243
253
}
244
254
245
255
gitTag := gitNormalizeForTagUsage (path .Join (arch , namespace , r .RepoName , entry .Tags [0 ]))
@@ -253,3 +263,20 @@ func (r Repo) fetchGitRepo(arch string, entry *manifest.Manifest2822Entry) (stri
253
263
entry .SetGitCommit (arch , commit )
254
264
return commit , nil
255
265
}
266
+
267
+ // this is used as a fallback if using github.com/go-git/go-git/v5 to fetch the branch fails to find the commit
268
+ // Git (and more recently, GitHub) support "git fetch"ing a specific commit directly!
269
+ // (The "actions/checkout@v2" GitHub action uses this to fetch commits for running workflows even after branches are deleted!)
270
+ // https://github.com/git/git/commit/f8edeaa05d8623a9f6dad408237496c51101aad8
271
+ // (Unfortunately, github.com/go-git/go-git/v5 does not support fetching a commit like this from what I can figure [https://github.com/go-git/go-git/issues/56], so we have to shell out.)
272
+ func fetchGitCommit (arch string , entry * manifest.Manifest2822Entry , gitRemote , fetchString string ) error {
273
+ commit := entry .ArchGitCommit (arch )
274
+ if commit == "FETCH_HEAD" {
275
+ return fmt .Errorf ("cannot fetch line-based entry commit when fetching by tag" )
276
+ }
277
+
278
+ fetchString = "+" + commit + ":" + strings .SplitN (fetchString , ":" , 2 )[1 ]
279
+
280
+ _ , err := git (`fetch` , `--quiet` , gitRemote , fetchString )
281
+ return err
282
+ }
0 commit comments