Skip to content

Commit

Permalink
tests/bud.bats: add git source
Browse files Browse the repository at this point in the history
Signed-off-by: danishprakash <danish.prakash@suse.com>
  • Loading branch information
danishprakash committed Apr 22, 2024
1 parent e504396 commit 1236851
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions define/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ func parseGitBuildContext(url string) (string, string, string) {
return gitBranchPart[0], gitSubdir, gitBranch
}

func isGitTag(remote, ref, dir string) (bool, error) {
func isGitTag(remote, ref string) bool {
if _, err := exec.Command("git", "ls-remote", "--exit-code", remote, ref).Output(); err != nil {
return true, nil
return true
}
return false, nil
return false
}

func cloneToDirectory(url, dir string) ([]byte, string, error) {
Expand All @@ -279,7 +279,7 @@ func cloneToDirectory(url, dir string) ([]byte, string, error) {
}

if gitRef != "" {
if ok, _ := isGitTag(url, gitRef, dir); ok {
if ok := isGitTag(url, gitRef); ok {
gitRef += ":refs/tags/" + gitRef
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6720,3 +6720,26 @@ _EOF
assert "$status" -eq 2 "exit code from ls"
expect_output --substring "No such file or directory"
}

@test "bud with ADD with git repository source" {
_prefetch alpine

local contextdir=${TEST_SCRATCH_DIR}/add-git
mkdir -p $contextdir
cat > $contextdir/Dockerfile << _EOF
FROM alpine
RUN apk add git
# branch check
ADD https://github.com/containers/buildah.git#release-1.35 /buildah-branch
RUN cd buildah-branch && \
[ "$(git rev-parse HEAD)" = "$(git ls-remote origin release-1.35 | cut -f1)" ] || exit 1
# tag check
ADD https://github.com/containers/buildah.git#v1.35.0 /buildah-tag
RUN cd buildah-tag && \
[ "$(git rev-parse HEAD)" = "$(git ls-remote --tags origin v1.35.0^{} | cut -f1)" ] || exit 1
_EOF

run_buildah build $WITH_POLICY_JSON -f $contextdir/Dockerfile
}

0 comments on commit 1236851

Please sign in to comment.