-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Respect .gitignore during cargo new
#5733
Respect .gitignore during cargo new
#5733
Conversation
r? @matklad (rust_highfive has picked a reviewer for you, use r? to override) |
cc @joshtriplett I figure you may be interested in this, since you filed #1210 way back. |
Looks good to me! Can you add a test for this as well? |
☔ The latest upstream changes (presumably #5723) made this pull request unmergeable. Please resolve the merge conflicts. |
This seems like a plausible heuristic. |
c259f89
to
4f2d554
Compare
@bors r=alexcrichton |
📌 Commit 4f2d55472c0d2a7f6f1931ad8441c110ea477c49 has been approved by |
⌛ Testing commit 4f2d55472c0d2a7f6f1931ad8441c110ea477c49 with merge 09f35b8c58816bd625e6125f727f9d7852229b8a... |
💔 Test failed - status-appveyor |
4f2d554
to
a63f31d
Compare
It appears this behavior doesn't work on windows, I am unable to test locally & attempts to fix path issues have been unsuccessful. |
I am a windows based lifeform, I am able to reproduce locally. Investigating. |
Does this fix it? dwijnand@ec27a6a |
edit: @dwijnand good thought, but no. I don't think it is the test. I don't think the functionality is working. I don't have any |
looks like code with println pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
fn in_git_repo(path: &Path, cwd: &Path) -> bool {
if let Ok(repo) = GitRepo::discover(path, cwd) {
println!("repo: {:?}", repo.path().display());
repo.is_path_ignored(path).map(|ignored| {
println!("path: {:?} ignored: {:?}", path.display(), ignored);
!ignored
}).unwrap_or(true)
} else { false }
}
in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok()
} full output: running 1 test
running `C:\\cargo\target\debug\cargo.exe new foo`
repo: "C:/cargo/.git/"
path: "C:\\cargo\\target\\cit\\t0" ignored: false
Created binary (application) `foo` project
thread 'new::subpackage_no_git' panicked at '
Expected: ExistingDir
but: C:\cargo\target\cit\t0\foo/.git was not a dir', tests\testsuite\hamcrest.rs:13:9
stack backtrace: the kee output is: repo: "C:/cargo/.git/"
path: "C:\\cargo\\target\\cit\\t0" ignored: false
|
Unintentional ping? Forwarding to @dwijnand. |
It sounds like Maybe for now we merge with this functionality only on unix & open a tracking issue for supporting it on windows? |
Yup, see https://github.com/alexcrichton/git2-rs/issues/334 |
Looks like We can wait for that PR and for a new version of libgit, or we can add the same workaround to this PR. Please don't leave a bunch of test broken on windows. |
I'm suggesting merging this PR by cfging out the one new test of this new functionality until the git2 patch has merged. |
In looking the new test to find this bug I realized that there are a lot of test that are nop, because they don't realize that no .git folders are created in target at all, and there are other test with workarounds for it. I guess we could clean that mess up when we get it working on windows. |
I'm with boats: let's accept the feature, with the test for Unix only, and forward fix trailing concerns. |
We can land this as a gated feature perhaps if it only works on Unix, but otherwise we can't land new functionality in Cargo that doesn't work on one of our tier 1 platforms |
Oh, sorry, I'm still confused thinking the failure is the test on Windows, rather than the feature itself. |
This should work with I'd like to see the other test reviewed before this gets merged, but as long as they pass we can clean them up later. |
This is failing CI validation because the pre-existing test I think the failure is a git2 error ( But, in the meanwhile, I've found you can tweak the test to make it pass by either:
|
When running `cargo new`, we check to see if you are inside a git repository. If you are, we do not initialize a new git repo for your project unless you specifically asked for it using --vcs. (See rust-lang#1210 for more background). This commit changes that behavior to *also* create a new repo if the project would be an ignored path in the parent repository. This way, if your home directory is a git repository, as long as you have ignored the directory you are creating a new project in, we will instantiate a git repository without you having to specifically request it.
a29dd74
to
064a146
Compare
@bors: r+ |
📌 Commit 064a146 has been approved by |
Thanks for the diagnosis @dwijnand! |
…excrichton Respect .gitignore during `cargo new` When running `cargo new`, we check to see if you are inside a git repository. If you are, we do not initialize a new git repo for your project unless you specifically asked for it using --vcs. (See #1210 for more background). This commit changes that behavior to *also* create a new repo if the project would be an ignored path in the parent repository. This way, if your home directory is a git repository, as long as you have ignored the directory you are creating a new project in, we will instantiate a git repository without you having to specifically request it.
☀️ Test successful - status-appveyor, status-travis |
now that we respect gitignore tests can be simplified There are a lot of test that used a tempfile to avoid the fact that cargo would not init a git in the test folder. (or because they were copy/pasted from one that did.) Now that #5733 landed we can remove them all.
now that we respect gitignore tests can be simplified There are a lot of test that used a tempfile to avoid the fact that cargo would not init a git in the test folder. (or because they were copy/pasted from one that did.) Now that #5733 landed we can remove them all.
When running
cargo new
, we check to see if you are inside a git repository. If you are, we do not initialize a new git repo for your project unless you specifically asked for it using --vcs. (See #1210 for more background).This commit changes that behavior to also create a new repo if the project would be an ignored path in the parent repository. This way, if your home directory is a git repository, as long as you have ignored the directory you are creating a new project in, we will instantiate a git repository without you having to specifically request it.