diff --git a/state/input.go b/state/input.go index 4506a24f..6072f6fd 100644 --- a/state/input.go +++ b/state/input.go @@ -139,10 +139,16 @@ func (git gitInput) Compile(_ string, _ *State) (*compiler.Value, error) { ref = git.Ref } + dir := "" + if git.Dir != "" { + dir = fmt.Sprintf(`,{do:"subdir", dir:"%s"}`, git.Dir) + } + return compiler.Compile("", fmt.Sprintf( - `#up: [{do:"fetch-git", remote:"%s", ref:"%s"}]`, + `#up: [{do:"fetch-git", remote:"%s", ref:"%s"}%s]`, git.Remote, ref, + dir, )) } diff --git a/tests/cli.bats b/tests/cli.bats index 01041356..94a90dff 100644 --- a/tests/cli.bats +++ b/tests/cli.bats @@ -336,12 +336,15 @@ setup() { @test "dagger input git" { "$DAGGER" init - dagger_new_with_plan input "$TESTDIR"/cli/input/artifact + ## Test simple input git + dagger_new_with_plan "input-simple-git" "$TESTDIR"/cli/input/artifact # input git - "$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git - "$DAGGER" up -e "input" - run "$DAGGER" -l error query -e "input" + "$DAGGER" -e "input-simple-git" input list + "$DAGGER" -e "input-simple-git" input git source "https://github.com/samalba/dagger-test-simple" + "$DAGGER" -e "input-simple-git" input list + "$DAGGER" -e "input-simple-git" up --no-cache + run "$DAGGER" -l error query -e "input-simple-git" assert_output '{ "bar": "testgit\n", "foo": "bar", @@ -349,12 +352,21 @@ setup() { }' # unset input git - "$DAGGER" input -e "input" unset "source" - "$DAGGER" up -e "input" - run "$DAGGER" -l error query -e "input" + "$DAGGER" input -e "input-simple-git" unset "source" + "$DAGGER" up -e "input-simple-git" + run "$DAGGER" -l error query -e "input-simple-git" assert_output '{ "foo": "bar" }' + + ## Test input git with subdir + dagger_new_with_plan "input-subdir-git" "$TESTDIR"/cli/input/git + + # input git + "$DAGGER" -e "input-subdir-git" input git TestRepo "https://github.com/dagger/examples" "main" "todoapp" + + # Assert success (test is directly in the cue file) + "$DAGGER" -e "input-subdir-git" up } @test "dagger input list" { diff --git a/tests/cli/input/git/main.cue b/tests/cli/input/git/main.cue new file mode 100644 index 00000000..bbdad7a8 --- /dev/null +++ b/tests/cli/input/git/main.cue @@ -0,0 +1,18 @@ +package testing + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/os" +) + +// Input https://github.com/dagger/examples/tree/main/todoapp +TestRepo: dagger.#Input & {dagger.#Artifact} + +// Check README.md +TestFolder: os.#Container & { + always: true + command: #""" + grep -q "Todo APP" /input/repo/README.md + """# + mount: "/input/repo": from: TestRepo +}