From 496273445e8f6047c4c18d55ed810676460d907d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 05:25:17 +0000 Subject: [PATCH] Copy .git in deploysource provider (#5442) (#5475) Signed-off-by: Shinnosuke Sawada-Dazai Signed-off-by: pipecd-bot Co-authored-by: Shinnosuke Sawada-Dazai --- pkg/app/piped/deploysource/deploysource.go | 11 +---------- pkg/app/pipedv1/deploysource/deploysource.go | 11 +---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/pkg/app/piped/deploysource/deploysource.go b/pkg/app/piped/deploysource/deploysource.go index ba62a6a86f..5809e459d8 100644 --- a/pkg/app/piped/deploysource/deploysource.go +++ b/pkg/app/piped/deploysource/deploysource.go @@ -203,17 +203,8 @@ func (p *provider) prepare(ctx context.Context, lw io.Writer) (*DeploySource, er func (p *provider) copy(lw io.Writer) (*DeploySource, error) { p.copyNum++ - src := p.source.RepoDir dest := fmt.Sprintf("%s-%d", p.source.RepoDir, p.copyNum) - - // use tar to exclude the .git directory - // the tar command does not create the destination directory if it does not exist. - // so we need to create it before running the command. - if err := os.MkdirAll(dest, 0700); err != nil { - fmt.Fprintf(lw, "Unable to create the directory to store the copied deploy source (%v)\n", err) - return nil, err - } - cmd := exec.Command("sh", "-c", fmt.Sprintf("tar c -f - -C '%s' --exclude='.git' . | tar x -f - -C '%s'", src, dest)) + cmd := exec.Command("cp", "-rf", p.source.RepoDir, dest) out, err := cmd.CombinedOutput() if err != nil { fmt.Fprintf(lw, "Unable to copy deploy source data (%v, %s)\n", err, string(out)) diff --git a/pkg/app/pipedv1/deploysource/deploysource.go b/pkg/app/pipedv1/deploysource/deploysource.go index 2637291ccd..e50e9b20f4 100644 --- a/pkg/app/pipedv1/deploysource/deploysource.go +++ b/pkg/app/pipedv1/deploysource/deploysource.go @@ -183,17 +183,8 @@ func (p *provider) prepare(ctx context.Context, lw io.Writer) (*DeploySource, er func (p *provider) copy(lw io.Writer) (*DeploySource, error) { p.copyNum++ - src := p.source.RepoDir dest := fmt.Sprintf("%s-%d", p.source.RepoDir, p.copyNum) - - // use tar to exclude the .git directory - // the tar command does not create the destination directory if it does not exist. - // so we need to create it before running the command. - if err := os.MkdirAll(dest, 0700); err != nil { - fmt.Fprintf(lw, "Unable to create the directory to store the copied deploy source (%v)\n", err) - return nil, err - } - cmd := exec.Command("sh", "-c", fmt.Sprintf("tar c -f - -C '%s' --exclude='.git' . | tar x -f - -C '%s'", src, dest)) + cmd := exec.Command("cp", "-rf", p.source.RepoDir, dest) out, err := cmd.CombinedOutput() if err != nil { fmt.Fprintf(lw, "Unable to copy deploy source data (%v, %s)\n", err, string(out))