-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the pull function so that tag-provided mirrors do not fetch all tags, instead later fetching (externally) only the tag they need. Implement tag fetching function to retrieve only the desired tag when creating a tag-provided repo mirror. Checkout the tag into a detatched HEAD state at the end of the create stage of tag-provided repository mirrors. Implement ref removal and addition functions used during package creation and mirror push to ensure that refs that aren't wanted on the mirror won't be pushed. Update the refspecs used in the push to push detatched HEAD, branches, online remote, and tags to the offline mirror. Note that if we later checkout a branch from the remote and do not clean up the remote ref it will lead to a duplicate ref name and the push will fail on one of the refs (likely the online one since it is later in the refspec slice). Fixes #154 feat: Allow for repos to be provided without a tag to mirror all branches/tags feat: Make tag-provided repository mirrors use the tag as master fix: Prevent tag-provided repo mirrors from storing extra refs fix: tag-provided clones use trunk branch name docs: Update gitops-data Example README
- Loading branch information
1 parent
b46d28c
commit 180fcef
Showing
8 changed files
with
458 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package git | ||
|
||
import ( | ||
"path" | ||
|
||
"github.com/go-git/go-git/v5" | ||
goConfig "github.com/go-git/go-git/v5/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// FetchTag performs a `git fetch` of _only_ the provided tag | ||
func FetchTag(gitDirectory string, tag string) { | ||
logContext := logrus.WithFields(logrus.Fields{ | ||
// Base should be similar to the repo name | ||
"Repo": path.Base(gitDirectory), | ||
}) | ||
|
||
repo, err := git.PlainOpen(gitDirectory) | ||
if err != nil { | ||
logContext.Fatal(err) | ||
} | ||
|
||
remotes, err := repo.Remotes() | ||
// There should never be no remotes, but it's easier to account for than | ||
// let be a bug later | ||
if err != nil || len(remotes) == 0 { | ||
if err != nil { | ||
logContext.Debug(err) | ||
} | ||
logContext.Fatal("Failed to identify remotes.") | ||
} | ||
|
||
gitUrl := remotes[0].Config().URLs[0] | ||
// Now that we have an exact match, we may as well update the logger, | ||
// especially since nothing has been logged to this point that hasn't been | ||
// fatal. | ||
logContext = logrus.WithFields(logrus.Fields{ | ||
"Remote": gitUrl, | ||
}) | ||
|
||
gitCred := FindAuthForHost(gitUrl) | ||
|
||
logContext.Debug("Attempting to find tag: " + tag) | ||
fetchOptions := &git.FetchOptions{ | ||
RemoteName: onlineRemoteName, | ||
RefSpecs: []goConfig.RefSpec{ | ||
goConfig.RefSpec("refs/tags/" + tag + ":refs/tags/" + tag), | ||
}, | ||
} | ||
|
||
if gitCred.Auth.Username != "" { | ||
fetchOptions.Auth = &gitCred.Auth | ||
} | ||
|
||
err = repo.Fetch(fetchOptions) | ||
|
||
if err == git.ErrTagExists { | ||
logContext.Info("Tag already fetched") | ||
} else if err != nil { | ||
logContext.Debug(err) | ||
logContext.Fatal("Not a valid tag or unable to fetch") | ||
} | ||
|
||
logContext.Info("Git tag fetched") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.