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

Generated .hgignore is invalid #4405

Closed
olivren opened this issue Aug 15, 2017 · 3 comments
Closed

Generated .hgignore is invalid #4405

olivren opened this issue Aug 15, 2017 · 3 comments

Comments

@olivren
Copy link

olivren commented Aug 15, 2017

When using cargo init or cargo new with --vcs hg, a .hgignore file is generated with the following content:

/target/
**/*.rs.bk
Cargo.lock

Mercurial supports two different syntaxes for ignoring files: regexp and glob. You can have different sections of the file that use either syntax, by declaring a line syntax: glob or syntax: regexp. An alternative is to prefix specific lines with glob: or regexp:. If no syntax is specified, it defaults to regexp.

The problem is that the .hgignore generated by cargo uses the glob syntax, but does not declare syntax: glob so Mercurial tries to interpret it as regexps, giving an error.

C:\Users\me\source\myproject>hg status
abort: C:\Users\me\source\myproject\.hgignore: invalid pattern (relre): **/*.rs.bk

The correct content should be:

^target/
\.rs\.bk$
^Cargo.lock$
  • ^target/ matches only the top-level directory "target"
  • \.rs\.bk$ matches all files ending with .rs.bk (patterns are not rooted, so this actually matches files in any directory)
  • ^Cargo.lock$ matches exactly the file "Cargo.lock"
@olivren
Copy link
Author

olivren commented Aug 15, 2017

In cargo/src/cargo/ops/cargo_new.rs, I can see this code:

let hgignore = ["^target/\n", "glob:*.rs.bk\n",
        if !opts.bin { "glob:Cargo.lock\n" } else { "" }]
.concat();

For some reason, I end up with the content of the variable ignore instead of this hgignore. Also note that glob:Cargo.lock matches a "Cargo.lock" file in any directory, not only the root.

@matklad
Copy link
Member

matklad commented Aug 16, 2017

@olivren are you by any change use a stable/beta Cargo? The fix you've found was implemented relatively recently: #4342

@olivren
Copy link
Author

olivren commented Aug 16, 2017

I was using stable and also a relatively recent nightly. I just updated to a more recent nightly that indeed contains the fix. Sorry about that, I'm closing this issue.

@olivren olivren closed this as completed Aug 16, 2017
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

No branches or pull requests

2 participants