Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for git-worktree #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions impl/create_srpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (bldr *srpmBuilder) fetchUpstream() error {
upstreamSrcType := bldr.pkgSpec.Type
var upstreamSrc *upstreamSrcSpec
var err error
if upstreamSrcType == "git-upstream" {
upstreamSrc, err = bldr.getUpstreamSourceForGit(upstreamSrcFromManifest, downloadDir)
if upstreamSrcType == "git-upstream" || upstreamSrcType == "git-worktree" {
upstreamSrc, err = bldr.getUpstreamSourceForGit(upstreamSrcFromManifest, upstreamSrcType, downloadDir)
} else {
upstreamSrc, err = bldr.getUpstreamSourceForOthers(upstreamSrcFromManifest, downloadDir)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func (bldr *srpmBuilder) verifyUpstream() error {
if err := bldr.verifyUpstreamSrpm(); err != nil {
return err
}
} else if bldr.pkgSpec.Type == "git-upstream" {
} else if bldr.pkgSpec.Type == "git-upstream" || bldr.pkgSpec.Type == "git-worktree" {
for _, upstreamSrc := range bldr.upstreamSrc {
if !upstreamSrc.skipSigCheck {
err := verifyGitSignature(upstreamSrc.pubKeyPath, upstreamSrc.gitSpec, bldr.errPrefix)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (bldr *srpmBuilder) setupRpmbuildTreeSrpm() error {
// also checks tarball signature
func (bldr *srpmBuilder) setupRpmbuildTreeNonSrpm() error {

supportedTypes := []string{"tarball", "standalone", "git-upstream"}
supportedTypes := []string{"tarball", "standalone", "git-upstream", "git-worktree"}
if !slices.Contains(supportedTypes, bldr.pkgSpec.Type) {
panic(fmt.Sprintf("%ssetupRpmbuildTreeNonSrpm called for unsupported type %s",
bldr.errPrefix, bldr.pkgSpec.Type))
Expand Down Expand Up @@ -345,7 +345,7 @@ func (bldr *srpmBuilder) setupRpmbuildTree() error {
return err
}
} else if bldr.pkgSpec.Type == "tarball" || bldr.pkgSpec.Type == "standalone" ||
bldr.pkgSpec.Type == "git-upstream" {
bldr.pkgSpec.Type == "git-upstream" || bldr.pkgSpec.Type == "git-worktree" {
if err := bldr.setupRpmbuildTreeNonSrpm(); err != nil {
return err
}
Expand Down
22 changes: 15 additions & 7 deletions impl/create_srpm_for_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ func generateArchiveFile(targetDir, clonedDir, revision, repo, pkg string, isPkg
}

// Download the git repo, and create a tarball at the provided commit/tag.
func archiveGitRepo(srcURL, targetDir, revision, repo, pkg string, isPkgSubdirInRepo bool,
func archiveGitRepo(srcURL, targetDir, upstreamSrcType, revision, repo, pkg string, isPkgSubdirInRepo bool,
errPrefix util.ErrPrefix) (string, string, error) {
cloneDir, err := cloneGitRepo(pkg, srcURL, revision, targetDir)
if err != nil {
return "", "", fmt.Errorf("cloning git repo failed: %s", err)
// If package type is "git-worktree",
// then the directory containing 'eext.yaml' is the source.
// TODO: Determine the directory based on final location on 'eext.yaml'
cloneDir := "."
if upstreamSrcType == "git-upstream" {
var err error
cloneDir, err = cloneGitRepo(pkg, srcURL, revision, targetDir)
if err != nil {
return "", "", fmt.Errorf("cloning git repo failed: %s", err)
}
}

gitArchiveFile, err := generateArchiveFile(targetDir, cloneDir, revision, repo, pkg, isPkgSubdirInRepo, errPrefix)
Expand All @@ -178,7 +185,7 @@ func archiveGitRepo(srcURL, targetDir, revision, repo, pkg string, isPkgSubdirIn
return gitArchiveFile, cloneDir, nil
}

func getGitSpecAndSrcFile(srcUrl, revision, downloadDir, repo, pkg string,
func getGitSpecAndSrcFile(srcUrl, revision, downloadDir, upstreamSrcType, repo, pkg string,
isPkgSubdirInRepo bool, errPrefix util.ErrPrefix) (*gitSpec, string, error) {
spec := gitSpec{
SrcUrl: srcUrl,
Expand All @@ -188,6 +195,7 @@ func getGitSpecAndSrcFile(srcUrl, revision, downloadDir, repo, pkg string,
sourceFile, clonedDir, downloadErr := archiveGitRepo(
srcUrl,
downloadDir,
upstreamSrcType,
revision,
repo, pkg, isPkgSubdirInRepo,
errPrefix)
Expand All @@ -200,7 +208,7 @@ func getGitSpecAndSrcFile(srcUrl, revision, downloadDir, repo, pkg string,
}

func (bldr *srpmBuilder) getUpstreamSourceForGit(upstreamSrcFromManifest manifest.UpstreamSrc,
downloadDir string) (*upstreamSrcSpec, error) {
upstreamSrcType, downloadDir string) (*upstreamSrcSpec, error) {

repo := bldr.repo
pkg := bldr.pkgSpec.Name
Expand All @@ -225,7 +233,7 @@ func (bldr *srpmBuilder) getUpstreamSourceForGit(upstreamSrcFromManifest manifes
bldr.log("creating tarball for %s from repo %s", pkg, srcParams.SrcURL)
srcUrl := srcParams.SrcURL
revision := upstreamSrcFromManifest.GitBundle.Revision
spec, sourceFile, err := getGitSpecAndSrcFile(srcUrl, revision, downloadDir,
spec, sourceFile, err := getGitSpecAndSrcFile(srcUrl, revision, downloadDir, upstreamSrcType,
repo, pkg, isPkgSubdirInRepo, bldr.errPrefix)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type Manifest struct {
}

func (m Manifest) sanityCheck() error {
allowedPkgTypes := []string{"srpm", "unmodified-srpm", "tarball", "standalone", "git-upstream"}
allowedPkgTypes := []string{"srpm", "unmodified-srpm", "tarball", "standalone", "git-upstream", "git-worktree"}

for _, pkgSpec := range m.Package {
if pkgSpec.Name == "" {
Expand Down Expand Up @@ -190,10 +190,10 @@ func (m Manifest) sanityCheck() error {
}

for _, upStreamSrc := range pkgSpec.UpstreamSrc {
if pkgSpec.Type == "git-upstream" {
if pkgSpec.Type == "git-upstream" || pkgSpec.Type == "git-worktree" {
specifiedUrl := (upStreamSrc.GitBundle.Url != "")
specifiedRevision := (upStreamSrc.GitBundle.Revision != "")
if !specifiedUrl {
if !specifiedUrl && pkgSpec.Type == "git-upstream" {
return fmt.Errorf("please provide the url for git repo of package %s", pkgSpec.Name)
}
if !specifiedRevision {
Expand Down
Loading