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

Start searching git config at new path #8886

Merged
merged 1 commit into from
Nov 24, 2020

Conversation

justfortherec
Copy link
Contributor

This lets cargo new follow includeIf blocks inside .gitignore.

Fixes #8882

I am not sure if removing the __CARGO_TEST_ROOT environment variable has any bad side effects. My quick grep of the repository didn't highlight anything in particular.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 23, 2020
@justfortherec justfortherec force-pushed the fix/8882/gitconfig-includeif branch from b8f32cd to d44d280 Compare November 23, 2020 12:26
@justfortherec
Copy link
Contributor Author

I am not entirely sure what causes the failed test on Windows (I have no way of reproducing it locally):

failures:

---- new::finds_git_author_in_included_config stdout ----
running `D:\a\cargo\cargo\target\debug\cargo.exe new foo/bar`
thread 'new::finds_git_author_in_included_config' panicked at '
Expected: execs
    but: exited with exit code: 101
--- stdout

--- stderr
error: Failed to create package `bar` at `D:\a\cargo\cargo\target\cit\t1230\foo/bar`

Caused by:
  invalid escape at a\cargo\cargo\target\cit\t1230\foo/.gitconfig; class=Config (7)
', crates\cargo-test-support\src\lib.rs:729:13

The way how the new test crafts paths matches what surrounding tests use (e.g. subpackage_git_with_gitignore). Still, something seems to go wrong with the backwards slashes on Windows. It could be the path in .gitconfig. I will try using explicit calls to join instead of one call with several path components in one argument.

@justfortherec
Copy link
Contributor Author

The test failed again ... with the same error. I assume the culprit is the forward slash in "gitdir:{}/". The block is ignored without the trailing slash on my local machine (Linux). I have pushed another attempt to fix this.

BTW: I am not force pushing the attempts to fix the problem to make it easier to review. Before merging I'd like to squash the (supposed) fixes into the first commit.

@justfortherec
Copy link
Contributor Author

This is progress: A new error.

failed to parse config file: unexpected text after closing quotes (in D:/a/cargo/cargo/target/cit/t1230/home/.gitconfig:2, column 47); class=Config (7)

libgit2 fails with this error message if the parsed element does not end in "]

From config_parse.c at line 145:

	if (line[rpos] != '"' || line[rpos + 1] != ']') {
		set_parse_error(reader, rpos, "unexpected text after closing quotes");
		git_buf_dispose(&buf);
		return -1;
	}

It's hard for me to see why this would not be the case in this test because I lack access to a Windows environment. Does anyone with more experience have a lead? @alexcrichton

@DJMcNab
Copy link

DJMcNab commented Nov 23, 2020

I use gitdir/i:{} (for ignore case IIRC) in my personal setup which uses this feature on windows - that might be worth a try.

@justfortherec
Copy link
Contributor Author

I use gitdir/i:{} (for ignore case IIRC) in my personal setup which uses this feature on windows - that might be worth a try.

Thanks, @DJMcNab, I'll give it a try.

tests/testsuite/new.rs Outdated Show resolved Hide resolved
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good to me and seems like the right fix, thanks!

tests/testsuite/new.rs Outdated Show resolved Hide resolved
@DJMcNab
Copy link

DJMcNab commented Nov 23, 2020

Yeah, I've just debugged it to the same thing @alexcrichton found.

I got it working by adding

.to_string()
.replace('\\', "/"),

to both paths
Which obviously is very not ideal, but at least it works.

@justfortherec
Copy link
Contributor Author

Yeah, I've just debugged it to the same thing @alexcrichton found.

I got it working by adding

.to_string()
.replace('\\', "/"),

to both paths
Which obviously is very not ideal, but at least it works.

Thanks a lot for helping out with debugging. So in fact it is still the same problem that I had supposedly fixed earlier.

I was under the assumption that .display() would be platform specific, i.e. use \ on Windows.

How do I go about this now? Just including .to_string().replace('\\', "/") would then probably break the tests on other platforms. Can a write specific tests for different platforms?

@DJMcNab
Copy link

DJMcNab commented Nov 23, 2020

I don't think it would matter on other platforms, since they wouldn't have \ in their paths.

@justfortherec
Copy link
Contributor Author

justfortherec commented Nov 23, 2020

I am not super happy with the hack but I can live with it. I'll squash the commits and rebase on master. Then this PR is ready to be merged from my side.

This lets `cargo new` follow `includeIf` blocks inside .gitignore.

Fixes rust-lang#8882
@justfortherec justfortherec force-pushed the fix/8882/gitconfig-includeif branch from e7d11b1 to 35b029c Compare November 23, 2020 19:44
@alexcrichton
Copy link
Member

@bors: r+

Sounds reasonable to me!

@bors
Copy link
Contributor

bors commented Nov 24, 2020

📌 Commit 35b029c has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2020
@bors
Copy link
Contributor

bors commented Nov 24, 2020

⌛ Testing commit 35b029c with merge 4e32fba...

@bors
Copy link
Contributor

bors commented Nov 24, 2020

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing 4e32fba to master...

@bors bors merged commit 4e32fba into rust-lang:master Nov 24, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 24, 2020
Update cargo

10 commits in 2af662e22177a839763ac8fb70d245a680b15214..bfca1cd22bf514d5f2b6c1089b0ded0ba7dfaa6e
2020-11-12 19:04:56 +0000 to 2020-11-24 16:33:21 +0000
- Shrink the progress bar, to give more space after it. (rust-lang/cargo#8892)
- Add some comments to the toml code (rust-lang/cargo#8887)
- Start searching git config at new path (rust-lang/cargo#8886)
- Fix documentation for CARGO_PRIMARY_PACKAGE. (rust-lang/cargo#8891)
- Bump to 0.51.0, update changelog (rust-lang/cargo#8894)
- Publish target's "doc" setting when emitting metadata (rust-lang/cargo#8869)
- Relaxes expectation of `cargo test` tests to accept test execution time (rust-lang/cargo#8884)
- Finish implementation of `-Zextra-link-arg`. (rust-lang/cargo#8441)
- Reproducible crate builds (rust-lang/cargo#8864)
- Allow resolver="1" to explicitly use the old resolver behavior. (rust-lang/cargo#8857)
@justfortherec justfortherec deleted the fix/8882/gitconfig-includeif branch November 24, 2020 21:19
bors added a commit that referenced this pull request Dec 2, 2020
Fix test escaping __CARGO_TEST_ROOT

#8886 added a test which unsets `__CARGO_TEST_ROOT`, but that environment variable is there for a reason. This causes problems as it causes that test to load the `.cargo/config` from the real home directory, which if it contains a `[cargo-new]` section, causes the test to fail.

The fix here is to change `find_tests_git_config` so that it behaves more like the real git config loader, but avoids escaping the test sandbox.  There are some subtle issues here, like #7469, which I believe should still work correctly.
@ehuss ehuss added this to the 1.50.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cargo new does not follow "includeIf" in .gitconfig
6 participants