Skip to content

Commit

Permalink
retry fetching patch repo if the error is invalid auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg committed Apr 24, 2022
1 parent bc9d81b commit dd7fd31
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ Available Commands:
help Help about any command
Flags:
--allow-stream-branches Allow import from stream branches
--basic-password string Basic auth password
--basic-username string Basic auth username
--branch-prefix string Branch prefix (replaces import-branch-prefix) (default "r")
--branch-suffix string Branch suffix to use for imported branches
--cdn-url string CDN URL to download blobs from (default "https://git.centos.org/sources")
--git-committer-email string Email of committer (default "[email protected]")
--git-committer-name string Name of committer (default "rockyautomation")
-h, --help help for srpmproc
Expand All @@ -31,9 +34,9 @@ Flags:
--ssh-key-location string Location of the SSH key to use to authenticate against upstream
--ssh-user string SSH User (default "git")
--storage-addr string Bucket to use as blob storage
--strict-branch-mode If enabled, only branches with the calculated name are imported and not prefix only
--tmpfs-mode string If set, packages are imported to path and patched but not pushed
--upstream-prefix string Upstream git repository prefix
--upstream-prefix-https string Web version of upstream prefix. Required if module-mode
--version int Upstream version
Use "srpmproc [command] --help" for more information about a command.
Expand Down
61 changes: 36 additions & 25 deletions pkg/srpmproc/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package srpmproc
import (
"encoding/json"
"fmt"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rocky-linux/srpmproc/pkg/misc"
"io/ioutil"
"log"
Expand Down Expand Up @@ -141,37 +142,47 @@ func executePatchesRpm(pd *data.ProcessData, md *data.ModeData) error {
pd.Log.Printf("set reference to ref: %s", refName)

if err != nil {
// no patches active
log.Println("info: patch repo not found")
return nil
} else {
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", "main"),
Force: true,
})
// common patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err == transport.ErrInvalidAuthMethod || err == transport.ErrAuthenticationRequired {
fetchOptions.Auth = nil
err = repo.Fetch(fetchOptions)
if err != nil {
return err
// no patches active
log.Println("info: patch repo not found")
return nil
}
} else {
log.Println("info: no common patches found")
// no patches active
log.Println("info: patch repo not found")
return nil
}
}

err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", md.PushBranch),
Force: true,
})
// branch specific patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no branch specific patches found")
err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", "main"),
Force: true,
})
// common patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no common patches found")
}

err = w.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewRemoteReferenceName("origin", md.PushBranch),
Force: true,
})
// branch specific patches found, apply them
if err == nil {
err := applyPatches(pd, md, w, md.Worktree)
if err != nil {
return err
}
} else {
log.Println("info: no branch specific patches found")
}

return nil
Expand Down

0 comments on commit dd7fd31

Please sign in to comment.