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

Allow Cargo new on existing empty dirs #781

Closed
wants to merge 1 commit into from
Closed

Allow Cargo new on existing empty dirs #781

wants to merge 1 commit into from

Conversation

aochagavia
Copy link
Contributor

No description provided.

@aochagavia aochagavia changed the title Allow on existing empty dirs Allow Cargo new on existing empty dirs Oct 30, 2014
@@ -23,9 +23,12 @@ struct CargoNewConfig {
}

pub fn new(opts: NewOptions, _shell: &mut MultiShell) -> CargoResult<()> {
fn dir_is_empty(p: &Path) { fs::walk_dir(p).unwrap().count() == 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is unwrap ok here? It doesn't look good, but I can't find a better alternative

@@ -23,9 +23,12 @@ struct CargoNewConfig {
}

pub fn new(opts: NewOptions, _shell: &mut MultiShell) -> CargoResult<()> {
fn dir_is_empty(p: &Path) -> bool { fs::walk_dir(p).unwrap().count() == 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is unwrap ok here? It doesn't look good, but I can't find a better alternative

@alexcrichton
Copy link
Member

Could you expand a little on the motivation for this? It may be a little too surprising to some that cargo new works on directories, but only on empty directories.

@aochagavia
Copy link
Contributor Author

I just thought this would be useful after having the following issue:

  1. cd into newproject and cargo new -> error (must specify a directory)
  2. Tried cargo new . -> error (directory already exists)

I think this is pretty surprising. With this PR I want to at least allow the second option.

Checking that the directory is not empty is just an easy way of ensuring no files will be overwritten, but it could also be done in a more fine-grained way.

@andrew-d
Copy link

andrew-d commented Nov 2, 2014

FWIW, I ran into this a couple times when starting with Cargo, since I tried cd path/to/code, git init foobar, cd foobar, cargo new .. It's definitely a small wart that would make things easier for new users.

@alexcrichton
Copy link
Member

Closing for now as I'd like to flesh out the cargo new story on existing directories more before implementing this, but thanks for the PR @aochagavia!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants