Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit ab2cb62

Browse files
committed
Fix failing checkout of master on trash -u
Sometimes `master` branch does not exist in the package repo. In this case we fetch and get the lastest commit available (from any branch).
1 parent dbb99ac commit ab2cb62

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

trash.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,22 @@ func checkout(trashDir string, i conf.Import) {
287287
}
288288
logrus.Infof("Checking out '%s', commit: '%s'", i.Package, i.Version)
289289
version := i.Version
290-
if isBranch(remoteName(i.Repo), i.Version) {
290+
if i.Version == "master" || isBranch(remoteName(i.Repo), i.Version) {
291291
version = remoteName(i.Repo) + "/" + i.Version
292+
if err := fetch(i); err != nil {
293+
logrus.WithFields(logrus.Fields{"i": i}).Fatalf("fetch failed")
294+
}
292295
}
293296
if bytes, err := exec.Command("git", "checkout", "-f", "--detach", version).CombinedOutput(); err != nil {
294297
logrus.Debugf("Error running `git checkout -f --detach %s`:\n%s", version, bytes)
295-
if err := fetch(i); err != nil {
298+
if i.Version == "master" {
299+
logrus.Warn("Failed to checkout 'master' branch: checking out the latest commit git can find")
300+
bytes, err := exec.Command("git", "log", "--all", "--pretty=oneline", "--abbrev-commit", "-1").Output()
301+
if err != nil {
302+
logrus.Fatalf("Failed to get latest commit with `git log --all --pretty=oneline --abbrev-commit -1`: %s", err)
303+
}
304+
version = strings.Fields(strings.TrimSpace(string(bytes)))[0]
305+
} else if err := fetch(i); err != nil {
296306
logrus.WithFields(logrus.Fields{"i": i}).Fatalf("fetch failed")
297307
}
298308
logrus.Debugf("Retrying!: `git checkout -f --detach %s`", version)

0 commit comments

Comments
 (0)