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

Adding a gitignore after the fact is difficult to clean up #3203

Open
peacememories opened this issue Mar 4, 2024 · 14 comments
Open

Adding a gitignore after the fact is difficult to clean up #3203

peacememories opened this issue Mar 4, 2024 · 14 comments

Comments

@peacememories
Copy link

Description

When adding files to the gitignore after jj has recognized them as new files, it is rather difficult to remove them from the automatically created commit again.

I ended up using git to manually create a new commit and work from there, but ideally, jj would recognize when a file added in the current commit has also been added to the gitignore.

Steps to Reproduce the Problem

  1. create a new repository somewhere with git init
  2. jj init --git-repo=.
  3. touch testfile
  4. jj st
  5. echo "testfile" > .gitignore
  6. jj st

Expected Behavior

Ideally, the testfile would not be part of the created commit.

Actual Behavior

testfile as well as .gitignore are marked as "added" in the commit.

Specifications

  • Platform: NixOS 23.11
  • Version: jj 0.13.0
@yuja
Copy link
Collaborator

yuja commented Mar 4, 2024

5. `echo "testfile" > .gitignore`
6. `jj st`

After the step 5, you'll need to run jj untrack testfile.

Perhaps, jj status can show hint for the added files matching .gitignore.

@peacememories
Copy link
Author

Ah thanks, I guess I missed untrack somehow. Adding a hint would be a good idea I think. I know some repos make use of the "committed but ignored file" behavior of git, but I think for most people it is unexpected.

@NoahTheDuke
Copy link

This has tripped me up before, and while jj untrack testfile works, it feel unintuitive compared to git's immediate respect of .gitignore.

@joyously
Copy link

joyously commented Mar 4, 2024

It seems just the opposite of #3204.
Does jj have its own ignore file also?

@martinvonz
Copy link
Member

We may want to consider the parent of the working copy when snapshotting the working copy. We currently only consider the previous snapshot of the working copy itself.

Does jj have its own ignore file also?

No. Maybe we will one day, or maybe not.

@joyously
Copy link

joyously commented Mar 4, 2024

Is there special handling for undo when the ignore file is involved?

@martinvonz
Copy link
Member

Is there special handling for undo when the ignore file is involved?

No

@PhilipMetzger
Copy link
Collaborator

This has tripped me up before, and while jj untrack testfile works, it feel unintuitive compared to git's immediate respect of .gitignore.

It makes sense though as it inverses the git add pattern which we cover with auto-tracking. But a hint for jj st is definitely a good idea.

@farnoy
Copy link
Collaborator

farnoy commented Mar 8, 2024

Encountered this as a fresh git convert. What compounded my confusion is that the documentation is outdated: https://github.com/martinvonz/jj/blob/6498a0cf8a5053e8a55fb503800e11b00953ecdc/docs/working-copy.md?plain=1#L60-L61 and contradicts an existing test case https://github.com/martinvonz/jj/blob/8e4d1af98eccf1ed8a79a7ddf9500467aa7684f5/cli/tests/test_gitignores.rs#L41-L47

@martinvonz
Copy link
Member

What compounded my confusion is that the documentation is outdated:

Thanks for letting us know! I'll send a PR to fix it.

@dbarnett
Copy link
Collaborator

+1 would love a hint to use untrack. Would it be better for status to include a hint (a) every time you run it while a file in the repo is committed + ignored or (b) once only after jj detects a new (git)ignore edit disagrees with the set of committed files?

@dbarnett
Copy link
Collaborator

An interesting special case of this: when switching the working copy to before/after .gitignore changes (see #4349). While it's not "wrong" for jj to leave the untracked file around and then snapshot them as new/deleted, that's especially frustrating and silent in jj vs. git (like after doing jj edit xyz; jj new main I can later discover junk files dirtying up xyz). I wonder if jj could explicitly detect those ignore changes as it updates the working copy and warn about them, if nothing else...

@martinvonz
Copy link
Member

+1 would love a hint to use untrack. Would it be better for status to include a hint (a) every time you run it while a file in the repo is committed + ignored or (b) once only after jj detects a new (git)ignore edit disagrees with the set of committed files?

I think every time you have a added file that's also ignored. I think we would have to implement that in the snapshotting code, so the working copy is the only thing that knows about the .gitignore files. I think @hooper was thinking of doing some refactoring of the gitignore code for a jj track command for tracking otherwise ignored files. I don't know if that would impact this feature.

@martinvonz
Copy link
Member

Btw, note that both listing untracked files (after #4338) and listing ignored-but-added files requires walking the working copy, which means these features won't work well with background snapshotting. I don't know what to do about that.

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

8 participants