Skip to content

Commit 752b5be

Browse files
committed
add: correctly resolve git tags and branches
Attempt to check if `tag` or `branch` exists on remote repo or not, if it does not exists then correctly report `error`. Closes: containers/podman#25679 Signed-off-by: flouthoc <[email protected]>
1 parent 243d897 commit 752b5be

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

add.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
518518
go func() {
519519
var cloneDir, subdir string
520520
cloneDir, subdir, getErr = define.TempDirForURL(tmpdir.GetTempDir(), "", src)
521+
defer pipeWriter.Close()
522+
defer wg.Done()
523+
if getErr != nil {
524+
return
525+
}
521526
getOptions := copier.GetOptions{
522527
UIDMap: srcUIDMap,
523528
GIDMap: srcGIDMap,
@@ -534,8 +539,6 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
534539
writer := io.WriteCloser(pipeWriter)
535540
repositoryDir := filepath.Join(cloneDir, subdir)
536541
getErr = copier.Get(repositoryDir, repositoryDir, getOptions, []string{"."}, writer)
537-
pipeWriter.Close()
538-
wg.Done()
539542
}()
540543
} else {
541544
go func() {

define/types.go

-13
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,6 @@ func parseGitBuildContext(url string) (string, string, string) {
260260
return gitBranchPart[0], gitSubdir, gitBranch
261261
}
262262

263-
func isGitTag(remote, ref string) bool {
264-
if _, err := exec.Command("git", "ls-remote", "--exit-code", remote, ref).Output(); err != nil {
265-
return true
266-
}
267-
return false
268-
}
269-
270263
func cloneToDirectory(url, dir string) ([]byte, string, error) {
271264
var cmd *exec.Cmd
272265
gitRepo, gitSubdir, gitRef := parseGitBuildContext(url)
@@ -284,12 +277,6 @@ func cloneToDirectory(url, dir string) ([]byte, string, error) {
284277
return combinedOutput, gitSubdir, fmt.Errorf("failed while performing `git remote add`: %w", err)
285278
}
286279

287-
if gitRef != "" {
288-
if ok := isGitTag(url, gitRef); ok {
289-
gitRef += ":refs/tags/" + gitRef
290-
}
291-
}
292-
293280
logrus.Debugf("fetching repo %q and branch (or commit ID) %q to %q", gitRepo, gitRef, dir)
294281
args := []string{"fetch", "-u", "--depth=1", "origin", "--", gitRef}
295282
cmd = exec.Command("git", args...)

tests/bud.bats

+9
Original file line numberDiff line numberDiff line change
@@ -7313,6 +7313,15 @@ _EOF
73137313
local_head_hash=$output
73147314
run_buildah run testctr -- sh -c 'cd podman-tag && git ls-remote --tags origin v5.0.0^{} | cut -f1'
73157315
assert "$output" = "$local_head_hash"
7316+
7317+
cat > $contextdir/Dockerfile << _EOF
7318+
FROM alpine
7319+
RUN apk add git
7320+
7321+
ADD https://github.com/openshift/microshift.git#foobar /src
7322+
_EOF
7323+
run_buildah 128 build -f $contextdir/Dockerfile -t git-image $contextdir
7324+
expect_output --substring "couldn't find remote ref foobar"
73167325
}
73177326

73187327
@test "build-validates-bind-bind-propagation" {

0 commit comments

Comments
 (0)