From 2b17c9f245b34f140f68abd6b91c6c9e4e1bb2bd Mon Sep 17 00:00:00 2001 From: nakabonne Date: Mon, 21 Dec 2020 12:47:14 +0900 Subject: [PATCH 1/4] Use OS-specific command to copy directory --- pkg/git/BUILD.bazel | 2 ++ pkg/git/command_darwin.go | 27 +++++++++++++++++++++++++++ pkg/git/command_linux.go | 25 +++++++++++++++++++++++++ pkg/git/repo.go | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pkg/git/command_darwin.go create mode 100644 pkg/git/command_linux.go diff --git a/pkg/git/BUILD.bazel b/pkg/git/BUILD.bazel index bcda26d65c..04b4934524 100644 --- a/pkg/git/BUILD.bazel +++ b/pkg/git/BUILD.bazel @@ -4,6 +4,8 @@ go_library( name = "go_default_library", srcs = [ "client.go", + "command_darwin.go", + "command_linux.go", "commit.go", "repo.go", "ssh_config.go", diff --git a/pkg/git/command_darwin.go b/pkg/git/command_darwin.go new file mode 100644 index 0000000000..6d7f98c942 --- /dev/null +++ b/pkg/git/command_darwin.go @@ -0,0 +1,27 @@ +// +build darwin + +// Copyright 2020 The PipeCD Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package git + +import ( + "os/exec" + "strings" +) + +func copyCommand(src, dst string) *exec.Cmd { + src = strings.TrimSuffix(src, "/") + return exec.Command("cp", "-rf", src+"/.", dst) +} diff --git a/pkg/git/command_linux.go b/pkg/git/command_linux.go new file mode 100644 index 0000000000..3aa2fe518a --- /dev/null +++ b/pkg/git/command_linux.go @@ -0,0 +1,25 @@ +// +build linux + +// Copyright 2020 The PipeCD Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package git + +import ( + "os/exec" +) + +func copyCommand(src, dst string) *exec.Cmd { + return exec.Command("cp", "-rf", src, dst) +} diff --git a/pkg/git/repo.go b/pkg/git/repo.go index b6b21c5350..9d5ce0a64d 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -77,7 +77,7 @@ func (r *repo) GetClonedBranch() string { // Copy does copying the repository to the given destination. func (r *repo) Copy(dest string) (Repo, error) { - cmd := exec.Command("cp", "-rf", r.dir, dest) + cmd := copyCommand(r.dir, dest) out, err := cmd.CombinedOutput() if err != nil { return nil, formatCommandError(err, out) From 285bf29760c50ea0dd9c78eb5032c61d99c61531 Mon Sep 17 00:00:00 2001 From: nakabonne Date: Tue, 22 Dec 2020 15:00:56 +0900 Subject: [PATCH 2/4] Revert "Use OS-specific command to copy directory" This reverts commit 2b17c9f245b34f140f68abd6b91c6c9e4e1bb2bd. --- pkg/git/BUILD.bazel | 2 -- pkg/git/command_darwin.go | 27 --------------------------- pkg/git/command_linux.go | 25 ------------------------- pkg/git/repo.go | 2 +- 4 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 pkg/git/command_darwin.go delete mode 100644 pkg/git/command_linux.go diff --git a/pkg/git/BUILD.bazel b/pkg/git/BUILD.bazel index 04b4934524..bcda26d65c 100644 --- a/pkg/git/BUILD.bazel +++ b/pkg/git/BUILD.bazel @@ -4,8 +4,6 @@ go_library( name = "go_default_library", srcs = [ "client.go", - "command_darwin.go", - "command_linux.go", "commit.go", "repo.go", "ssh_config.go", diff --git a/pkg/git/command_darwin.go b/pkg/git/command_darwin.go deleted file mode 100644 index 6d7f98c942..0000000000 --- a/pkg/git/command_darwin.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build darwin - -// Copyright 2020 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package git - -import ( - "os/exec" - "strings" -) - -func copyCommand(src, dst string) *exec.Cmd { - src = strings.TrimSuffix(src, "/") - return exec.Command("cp", "-rf", src+"/.", dst) -} diff --git a/pkg/git/command_linux.go b/pkg/git/command_linux.go deleted file mode 100644 index 3aa2fe518a..0000000000 --- a/pkg/git/command_linux.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build linux - -// Copyright 2020 The PipeCD Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package git - -import ( - "os/exec" -) - -func copyCommand(src, dst string) *exec.Cmd { - return exec.Command("cp", "-rf", src, dst) -} diff --git a/pkg/git/repo.go b/pkg/git/repo.go index 9d5ce0a64d..b6b21c5350 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -77,7 +77,7 @@ func (r *repo) GetClonedBranch() string { // Copy does copying the repository to the given destination. func (r *repo) Copy(dest string) (Repo, error) { - cmd := copyCommand(r.dir, dest) + cmd := exec.Command("cp", "-rf", r.dir, dest) out, err := cmd.CombinedOutput() if err != nil { return nil, formatCommandError(err, out) From 440e5575b05b5eb1c9492d4aa780aa1ca683131e Mon Sep 17 00:00:00 2001 From: nakabonne Date: Tue, 22 Dec 2020 15:05:13 +0900 Subject: [PATCH 3/4] Add notes on copying git repository --- pkg/git/repo.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/git/repo.go b/pkg/git/repo.go index b6b21c5350..e634eb951f 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -76,6 +76,7 @@ func (r *repo) GetClonedBranch() string { } // Copy does copying the repository to the given destination. +// NOTE: the given “dest” must be a path that doesn’t exist yet. func (r *repo) Copy(dest string) (Repo, error) { cmd := exec.Command("cp", "-rf", r.dir, dest) out, err := cmd.CombinedOutput() From 0580d9420879ed4322e19c5e6a82222bac7cf1ce Mon Sep 17 00:00:00 2001 From: nakabonne Date: Tue, 22 Dec 2020 15:11:24 +0900 Subject: [PATCH 4/4] Update notes --- pkg/git/repo.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/git/repo.go b/pkg/git/repo.go index e634eb951f..d5ba9ed299 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -77,6 +77,7 @@ func (r *repo) GetClonedBranch() string { // Copy does copying the repository to the given destination. // NOTE: the given “dest” must be a path that doesn’t exist yet. +// If you don't, it copies the repo root itself to the given dest as a subdirectory. func (r *repo) Copy(dest string) (Repo, error) { cmd := exec.Command("cp", "-rf", r.dir, dest) out, err := cmd.CombinedOutput()