diff --git a/impl/create_srpm.go b/impl/create_srpm.go index ebf4ee0..18c1032 100644 --- a/impl/create_srpm.go +++ b/impl/create_srpm.go @@ -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) } @@ -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) @@ -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)) @@ -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 } diff --git a/impl/create_srpm_for_git.go b/impl/create_srpm_for_git.go index 367b755..ec9c027 100644 --- a/impl/create_srpm_for_git.go +++ b/impl/create_srpm_for_git.go @@ -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) @@ -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, @@ -188,6 +195,7 @@ func getGitSpecAndSrcFile(srcUrl, revision, downloadDir, repo, pkg string, sourceFile, clonedDir, downloadErr := archiveGitRepo( srcUrl, downloadDir, + upstreamSrcType, revision, repo, pkg, isPkgSubdirInRepo, errPrefix) @@ -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 @@ -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 diff --git a/manifest/manifest.go b/manifest/manifest.go index 5296447..24875fe 100644 --- a/manifest/manifest.go +++ b/manifest/manifest.go @@ -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 == "" { @@ -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 {