From 096c936aafdeb6b9a7bca7baaa6d54f65dd7f4e9 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 10 Mar 2022 13:24:20 -0700 Subject: [PATCH] removes old .gitignore, adds new .gitattributes Signed-off-by: Richard Jones --- pkg/pkg.go | 15 ++++++++++++--- tests/project.bats | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/pkg.go b/pkg/pkg.go index f5680a48..13757962 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io/fs" + "io/ioutil" "os" "path" "path/filepath" @@ -61,10 +62,18 @@ func Vendor(ctx context.Context, p string) error { return err } - // generate `.gitignore` + // remove 0.1-style .gitignore files + gitignorePath := path.Join(cuePkgDir, ".gitignore") + if contents, err := ioutil.ReadFile(gitignorePath); err == nil { + if strings.HasPrefix(string(contents), "# generated by dagger") { + os.Remove(gitignorePath) + } + } + + // generate `.gitattributes` file if err := os.WriteFile( - path.Join(cuePkgDir, ".gitignore"), - []byte(fmt.Sprintf("# generated by dagger\ndagger.lock\n%s", strings.Join(modules, "\n"))), + path.Join(cuePkgDir, ".gitattributes"), + []byte("# generated by dagger\n** linguist-generated\n"), 0600, ); err != nil { return err diff --git a/tests/project.bats b/tests/project.bats index 4b8b409a..111c073e 100644 --- a/tests/project.bats +++ b/tests/project.bats @@ -2,13 +2,13 @@ setup() { load 'helpers' common_setup + + TEMPDIR=$(mktemp -d) } @test "project init and update" { - TEMPDIR=$(mktemp -d) - echo "TEMPDIR=$TEMPDIR" - cd "$TEMPDIR" - + cd "$TEMPDIR" || exit + "$DAGGER" project init ./ --name "github.com/foo/bar" test -d ./cue.mod/pkg test -d ./cue.mod/usr @@ -16,7 +16,15 @@ setup() { contents=$(cat ./cue.mod/module.cue) [ "$contents" == 'module: "github.com/foo/bar"' ] - dagger project update + # ensure old 0.1 style .gitignore is removed + printf "# generated by dagger\ndagger.lock" > .gitignore + + "$DAGGER" project update test -d ./cue.mod/pkg/dagger.io test -d ./cue.mod/pkg/universe.dagger.io + test -f ./cue.mod/pkg/.gitattributes + run cat ./cue.mod/pkg/.gitattributes + assert_output --partial "generated by dagger" + + test ! -f ./cue.mod/pkg/.gitignore }