Improve/git: Git.#Repository's origin now uses the provided URL

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville 2021-10-04 16:45:20 +02:00
parent 93284292e9
commit ce02caff51
2 changed files with 53 additions and 11 deletions

View File

@ -29,6 +29,13 @@ import (
authHeader: dagger.#Input & {*null | dagger.#Secret} authHeader: dagger.#Input & {*null | dagger.#Secret}
#up: [ #up: [
op.#Load & {
from: alpine.#Image & {
package: git: "=~2.30"
}
},
op.#Copy & {
from: [
op.#FetchGit & { op.#FetchGit & {
"remote": remote "remote": remote
"ref": ref "ref": ref
@ -42,6 +49,28 @@ import (
"authHeader": authHeader "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 { if subdir != null {
op.#Subdir & { op.#Subdir & {
dir: subdir dir: subdir

View File

@ -96,3 +96,16 @@ TestPrivateRepository: os.#Container & {
[ -d .git ] [ -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" ]]
"""
}