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

jj untrack foo~ fails #4509

Open
0-wiz-0 opened this issue Sep 20, 2024 · 10 comments
Open

jj untrack foo~ fails #4509

0-wiz-0 opened this issue Sep 20, 2024 · 10 comments

Comments

@0-wiz-0
Copy link

0-wiz-0 commented Sep 20, 2024

Description

emacs writes backup files with a ~ (tilde) at the end. jj automatically picks them up if you forgot to ignore them in the .gitignore file.
I can't untrack them in the latest version any longer. (I think this worked when it was jj untrack, but now it doesn't with jj file untrack, but perhaps I misremember.)

Steps to Reproduce the Problem

  1. jj git init
  2. touch foo~
  3. jj
  4. jj file untrack foo~
jj file untrack foo\~
Error: Failed to parse fileset: Syntax error
Caused by:  --> 1:5
  |
1 | foo~
  |     ^---
  |
  = expected `~` or <primary>

Specifications

  • Platform: NetBSD/10.99.12/amd64
  • Version: 0.21.0
@yuja
Copy link
Collaborator

yuja commented Sep 20, 2024

Since fileset is enabled by default, ~ has to be quoted: '"foo~"' or 'glob:"*~"'.
https://martinvonz.github.io/jj/latest/filesets/

Maybe we can add a hint if the expression looks like an existing path.

@0-wiz-0
Copy link
Author

0-wiz-0 commented Sep 20, 2024

From a quick read of the linked page: ~ seems only to be supported as a separate word, or at the start of a word, so perhaps making that an explicit requirement would also solve this.

@yuja
Copy link
Collaborator

yuja commented Sep 20, 2024

Yeah, trailing ~ could be special cased, but I don't think it's worth the added oddity. *~ is usually a backup file and so often ignored by .gitignore or user ignore.

x~y and ~x are valid syntax, btw.

@emilazy
Copy link
Collaborator

emilazy commented Sep 20, 2024

You can add this stuff to your global Git ignores in ~/.config, by the way.

@samueltardieu
Copy link
Collaborator

The message is now:

Error: Failed to parse fileset: Syntax error
Caused by:  --> 1:5
  |
1 | foo~
  |     ^---
  |
  = expected `~` or <primary>
Hint: See https://martinvonz.github.io/jj/latest/filesets/ for filesets syntax, or for how to match file paths.

Hopefully this is a clearer message. If this is, might we close this issue?

@0-wiz-0
Copy link
Author

0-wiz-0 commented Oct 8, 2024

I accept that I'm the only one annoyed by the change in behaviour between the old 'jj untrack' and the new 'jj file untrack' and have worked around it by having my global git config ignore "*~" files.

As for the actual change - I think this needs improvements in the documentation.
I read expected ~ or <primary> as that jj would expect a second tilde or a <primary> after the first tilde.
Both alternatives are unclear to me.
Neither https://martinvonz.github.io/jj/latest/filesets/ nor the page it links to from 'must be quoted', https://martinvonz.github.io/jj/latest/templates/#string-literals , mention ~~, and in my reading of https://martinvonz.github.io/jj/latest/templates/#string-literals I don't see a mention of how I should quote ~ at all, since the full list of backslash-quoted characters doesn't include the tilde
The word primary is not mentioned in the filesets page at all, so I don't know what a <primary> is either.

@martinvonz
Copy link
Owner

the change in behaviour between the old 'jj untrack' and the new 'jj file untrack'

FYI, I don't think it's a difference between jj untrack and jj file untrack. jj untrack actually still exists as an alias. What changed is that we enabled filesets by default.

I read expected ~ or <primary> as that jj would expect a second tilde or a <primary> after the first tilde.

~ is simply an operator for subtraction/difference (that's why it looks similar to -, which we chose not to use because it's so common in filenames).

A second tilde followed by an expression would make the syntax correct, but it's probably not what. The error message is generated by the low-level parsing code without understanding what makes a useful expression. foo~~bar means "file foo but not (not file bar)`, i.e. an empty set.

I think you can think of a <primary> is a fileset expression.

Neither https://martinvonz.github.io/jj/latest/filesets/ nor the page it links to from 'must be quoted',

That page includes this:

File names passed to these commands must be quoted if they contain whitespace or meta characters.

In foo~, the ~ is such a "meta character". @yuja, should we simply call it "operator" for simplicity? I'm guessing "meta characters" also includes the : in glob: etc., but do we need make that distinction? If we do, we should probably document it.

As for the actual change - I think this needs improvements in the documentation.

I'm not arguing with this. The above is just to explain how it actually works.

@ilyagr
Copy link
Collaborator

ilyagr commented Oct 8, 2024

Maybe we can add a hint if the expression looks like an existing path.

This sounds like a good idea to me, it's consistent with what we try to do in other similar cases. I just wanted to resurface it so that it doesn't get lost in the discussion.

@ilyagr
Copy link
Collaborator

ilyagr commented Oct 8, 2024

One (not fully thought through) possibility for improving the docs would be to change the URL in the error Samuel quoted in #4509 (comment) to link to a section, e.g. https://martinvonz.github.io/jj/latest/filesets/#syntax-error. Then, we could put a few examples into that section (mainly for unexpected syntax errors).

I was originally going to suggest combining this with Yuya's idea I quoted in my previous message, but while doing both makes sense to me, maybe having the URL would work even without implementing an error specific to patterns that look like files.

@yuja
Copy link
Collaborator

yuja commented Oct 8, 2024

In foo~, the ~ is such a "meta character". @yuja, should we simply call it "operator" for simplicity? I'm guessing "meta characters" also includes the : in glob: etc., but do we need make that distinction?

I just thought "meta character" is more abstract and easier to imagine than "operator". If we need a strict definition, maybe we can add a link to the grammar file?

Maybe we can add a hint if the expression looks like an existing path.

This sounds like a good idea to me, it's consistent with what we try to do in other similar cases.

I thought this would be a nice addition, but I think the current state (a hint with doc URL) is pretty good. We can improve the doc by adding more bad/good examples. (If I were new to jj, I would probably search the doc by error message.)

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

6 participants