-
Notifications
You must be signed in to change notification settings - Fork 210
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
Conversation
|
Code coverage for golang is
|
pkg/git/command_darwin.go
Outdated
|
|
||
| func copyCommand(src, dst string) *exec.Cmd { | ||
| src = strings.TrimSuffix(src, "/") | ||
| return exec.Command("cp", "-rf", src+"/.", dst) |
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 cp command 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 -r puts the directory you're copying into the destination directory.
❯ ls -a /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/srcdir/
./ ../ .git/ Dockerfile client/ client2/ go.mod go.sum main.go
❯ cp -rf /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/srcdir /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/dstdir
❯ ls -a /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/dstdir
./ ../ srcdir/
We can copy only the files under the srcdir by keeping the trailing slash for srcdir:
❯ cp -rf /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/srcdir/ /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/dstdir
❯ ls -a /var/folders/dn/4wqz0bq15x5_5zpxf1grd455pmlkzw/T/dstdir
./ ../ .git/ Dockerfile client/ client2/ go.mod go.sum main.go
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.
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 src path is / if I guess right? 🤔
besides, I checked on my macOS environment, src/path/ and src/path// have the same effect to the cp command 😅 I think we could simplify this logic here as just add the '/' character to the end of src path. 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 cp Linux command has the same behavior as macOS command, which means cp -r will copy the entry directory as a subdirectory of the dist path. If you want to just copy all subdirectories and files of the src directory to the dist path, you should add * to the end of the src path in case of using the Linux cp command.
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.
|
/hold |
| } | ||
|
|
||
| // Copy does copying the repository to the given destination. | ||
| func (r *repo) Copy(dest string) (Repo, error) { |
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.
@nghialv btw, perhaps was this method originally created for copying the repo root to the given dest as a subdirectory?
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.
@nghialv If so, my usage is just evil.
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.
But even if so, it's not appropriate to give back Repo. Well, it's nothing!
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.
The Copy function copies all the data of the original repository into a new directory.
And it expects the destination directory was not created before passing to this function.
I am sorry for the lack of explanation. We should have at least a comment.
From the current situation, I think we have 2 options:
- keep the current behavior and add a comment to explain that the dest directory must not be created before
- require the user to ensure that the directory must be created before passing to this function and change the command to
cp -rf src/* dest
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.
One vote for the first option. In the second context, The behaviors are slightly different depending on the cp command implementation (mostly BSD and GNU). Actually cp -rf src/* dest doesn't copy the hidden files including .git/ and so on.
Let me keep the current behavior and just add a comment!
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.
👍
|
Fixed done. |
**What this PR does / why we need it**: Usage of copying repo became clear from the discussion on #1296 **Which issue(s) this PR fixes**: Fixes # **Does this PR introduce a user-facing change?**: <!-- If no, just write "NONE" in the release-note block below. --> ```release-note NONE ``` This PR was merged by Kapetanios.
|
/hold cancel |
What this PR does / why we need it:
On MacOS, BSD's
cpcommand is installed by default. So the behavior is slightly different from GNU's one.This PR will cause the build of the binary for Windows to fail. I don't mind add
command_windows.goif it seems to be a problem.Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?: