From ce02caff51d348473b7f99ff1426d3843b6014b3 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Mon, 4 Oct 2021 16:45:20 +0200 Subject: [PATCH] Improve/git: Git.#Repository's origin now uses the provided URL Signed-off-by: Guillaume de Rouville --- stdlib/git/git.cue | 51 ++++++++++++++++++++++++++++-------- stdlib/git/tests/git/git.cue | 13 +++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/stdlib/git/git.cue b/stdlib/git/git.cue index 5a7e338e..c87a0933 100644 --- a/stdlib/git/git.cue +++ b/stdlib/git/git.cue @@ -29,19 +29,48 @@ import ( authHeader: dagger.#Input & {*null | dagger.#Secret} #up: [ - op.#FetchGit & { - "remote": remote - "ref": ref - if (keepGitDir) { - keepGitDir: true - } - if (authToken != null) { - "authToken": authToken - } - if (authHeader != null) { - "authHeader": authHeader + op.#Load & { + from: alpine.#Image & { + package: git: "=~2.30" } }, + op.#Copy & { + from: [ + op.#FetchGit & { + "remote": remote + "ref": ref + if (keepGitDir) { + keepGitDir: true + } + if (authToken != null) { + "authToken": authToken + } + if (authHeader != null) { + "authHeader": authHeader + } + }, + ] + dest: "/repository" + }, + op.#Exec & { + dir: "/repository" + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "-c", + #""" + code=$(git rev-parse --is-inside-work-tree 2>&1) + ([ "$code" = "true" ] && git remote set-url origin "$REMOTE") || true + """#, + ] + env: REMOTE: remote + }, + op.#Subdir & { + dir: "/repository" + }, if subdir != null { op.#Subdir & { dir: subdir diff --git a/stdlib/git/tests/git/git.cue b/stdlib/git/tests/git/git.cue index ca7a675c..46916318 100644 --- a/stdlib/git/tests/git/git.cue +++ b/stdlib/git/tests/git/git.cue @@ -96,3 +96,16 @@ TestPrivateRepository: os.#Container & { [ -d .git ] """ } + +TestReferenceFormat: os.#Container & { + image: alpine.#Image & { + package: bash: "=5.1.0-r0" + package: git: true + } + mount: "/repo1": from: privateRepo + dir: "/repo1" + command: """ + URL="$(git ls-remote --get-url origin)" + [[ "$URL" = "https://github.com/dagger/dagger.git" ]] + """ +}