Skip to content
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

Fix cp to match unix behavior #271

Merged
merged 3 commits into from Jan 16, 2016
Merged

Fix cp to match unix behavior #271

merged 3 commits into from Jan 16, 2016

Conversation

freitagbr
Copy link
Contributor

Fixes #256, #101.

@nfischer
Copy link
Member

nfischer commented Jan 6, 2016

It might be helpful to add unit tests for this behavior. When I ran a quick test, it seemed to work as expected.

@ariporad ariporad added the fix Bug/defect, or a fix for such a problem label Jan 9, 2016
@nfischer
Copy link
Member

@freitagbr Could you rebase off master?

Brandon Freitag and others added 2 commits January 11, 2016 01:32
In unix, if src is a directory and dest doesn't exist, 'cp -r src dest' will copy src/* into dest. Fix cp('-r', 'src', 'dest') to behave the same way.
@freitagbr
Copy link
Contributor Author

@nfischer Done.

@nfischer
Copy link
Member

Looks like some of the tests are still failing. If we could get these fixed (or have the tests adjusted, if appropriate), that'd be good

@@ -125,17 +125,23 @@ assert.equal(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); //

//recursive, creates dest dir since it's only one level deep (see Github issue #44)
shell.rm('-rf', 'tmp/*');
shell.cp('-r', 'resources/issue44/*', 'tmp/dir2');
shell.cp('-r', 'resources/issue44', 'tmp/dir2');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these test cases be changed? What was wrong with the previous behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In *nix, cp -r resources/issue44/* tmp/dir2 is not valid. If there is only one file in resources/issue44, it will be copied into tmp and be renamed dir2. If there is more than one file in resources/issue44, the command will fail.

The intention here is to copy all of the files in resources/issue44 to tmp/dir2, where dir2 will be created. This is achieved with the new command (and in *nix as well).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome explanation! The logic sounds right to me. It sounds like this is indeed a bug in the test. Thanks for fixing!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely!

@nfischer
Copy link
Member

LGTM! @ariporad

ariporad added a commit that referenced this pull request Jan 16, 2016
@ariporad ariporad merged commit 2c63ecf into shelljs:master Jan 16, 2016
@freitagbr freitagbr deleted the fix-cp-behavior branch January 26, 2016 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug/defect, or a fix for such a problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants