-
Notifications
You must be signed in to change notification settings - Fork 300
Add notes on copying git repository #1296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nghialv btw, perhaps was this method originally created for copying the repo root to the given
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nghialv If so, my usage is just evil.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But even if so, it's not appropriate to give back Repo. Well, it's nothing!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The From the current situation, I think we have 2 options:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One vote for the first option. In the second context, The behaviors are slightly different depending on the Let me keep the current behavior and just add a comment!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits, does the
cpcommand not work without the.at the end of src path? 👀There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too. Not sure why do we need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MacOS's
cp -rputs the directory you're copying into the destination directory.We can copy only the files under the srcdir by keeping the trailing slash for srcdir:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the trailing
.is unneeded.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, then this part is to ensure the last character of
srcpath is/if I guess right? 🤔besides, I checked on my macOS environment,
src/path/andsrc/path//have the same effect to thecpcommand 😅 I think we could simplify this logic here asjust add the '/' characterto the end ofsrcpath. How do you think about that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I'll do so after gaining everyone's agreements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked on my Linux environment, looks like the
cpLinux command has the same behavior as macOS command, which meanscp -rwill copy the entry directory as a subdirectory of thedistpath. If you want to just copy all subdirectories and files of thesrcdirectory to the dist path, you should add*to the end of thesrcpath in case of using the Linuxcpcommand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it true? Seems like I need to look into it more.