diff --git a/plugin.go b/plugin.go index d910eb9..ece6d05 100644 --- a/plugin.go +++ b/plugin.go @@ -116,8 +116,10 @@ func globList(paths []string) fileList { func buildArgs(tar string, files fileList) []string { args := []string{} if len(files.Ignore) > 0 { - args = append(args, "--exclude") - args = append(args, files.Ignore...) + for _, v := range files.Ignore { + args = append(args, "--exclude") + args = append(args, v) + } } args = append(args, "-cf") args = append(args, getRealPath(tar)) diff --git a/plugin_test.go b/plugin_test.go index 0a1013b..188f54d 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -261,7 +261,7 @@ func TestIgnoreList(t *testing.T) { Username: "drone-scp", Port: "22", KeyPath: "tests/.ssh/id_rsa", - Source: []string{"tests/global/*", "!tests/global/c.txt"}, + Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"}, StripComponents: 2, Target: []string{filepath.Join(u.HomeDir, "ignore")}, CommandTimeout: 60, @@ -277,6 +277,11 @@ func TestIgnoreList(t *testing.T) { t.Fatal("c.txt file exist") } + // check file exist + if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/e.txt")); err == nil { + t.Fatal("c.txt file exist") + } + if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/d.txt")); os.IsNotExist(err) { t.Fatalf("SCP-error: %v", err) } @@ -407,12 +412,12 @@ func TestGlobList(t *testing.T) { func TestBuildArgs(t *testing.T) { list := fileList{ - Source: []string{"tests/a.txt", "tests/b.txt"}, - Ignore: []string{"tests/a.txt"}, + Source: []string{"tests/a.txt", "tests/b.txt", "tests/c.txt"}, + Ignore: []string{"tests/a.txt", "tests/b.txt"}, } result := buildArgs("test.tar.gz", list) - expects := []string{"--exclude", "tests/a.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt"} + expects := []string{"--exclude", "tests/a.txt", "--exclude", "tests/b.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt", "tests/c.txt"} assert.Equal(t, expects, result) list = fileList{ diff --git a/tests/global/e.txt b/tests/global/e.txt new file mode 100644 index 0000000..e69de29