FR: Add a `jj track` command for tracking otherwise ignored files
Is your feature request related to a problem? Please describe.
If you have ignored files that you want to track, you currently have to temporary un-ignore them, which can be quite annoying, especially if they're in a directory that's ignored (unless you want to track everything in that directory).
Describe the solution you'd like
jj track <pattern> seems logical (we already have jj untrack <pattern>).
track is a pretty easy command to implement, but it has some interesting overlap with the ignore mechanism. If there is a track, should untrack automatically add a file to be ignored (with track also removing from the set of ignored files)?
untrack doesn't currently automatically add files to the ignore patterns, mostly because it's not clear if the user wants that particular file or a more general pattern to be ignored. @hooper, did you say you're also looking into this?
Not really.
I'm trying to implement track by refactoring GitIgnoreFile into a trait to allow it to interact with an impl that uses a Matcher, so I can just construct that and plug it into snapshot().
It would be a more invasive change to act further on the decisions to ignore paths during snapshot by persisting them. I agree with Martin that there are issues with defining a good UX for that.
Such a feature could become unpopular for spamming .gitignore files with confusing entries, even if we do some basic optimizations. Then it might turn into a tempting target for scope creep to "fix" that. Also, it's not obvious to me that every <pattern> we might want to accept would map reasonably to .gitignore patterns. For examples of how that could get harder or more ambiguous in the future, see https://github.com/martinvonz/jj/issues/2915.
I've occasionally imagined something like jj [un]ignore <pattern> that does this more directly, but it would have at least as many issues as doing it during [un]track.
Another detail we would want to consider is the UX for how we determine which .gitignore file we manipulate under which circumstances. I don't think something along the lines of jj config set --user|--repo would be sufficient.
So, I don't mean to shoot the idea down entirely, but I don't think it's low hanging fruit.
I want this for the case where I've ignored a file in my global ~/.git/config/ignore but I want to have it tracked in one specific repository. It's not ignored by that repository's local .gitignore so I don't think it's appropriate to add my own !... pattern to that file because of my global ignores. I did find a workaround of temporarily adding a negative pattern to .gitignore, running jj st so it starts tracking it, then deleting the pattern from .gitignore.