jj icon indicating copy to clipboard operation
jj copied to clipboard

Adding a gitignore after the fact is difficult to clean up

Open peacememories opened this issue 1 year ago • 16 comments

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

peacememories avatar Mar 04 '24 09:03 peacememories

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.

yuja avatar Mar 04 '24 10:03 yuja

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.

peacememories avatar Mar 04 '24 12:03 peacememories

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

NoahTheDuke avatar Mar 04 '24 14:03 NoahTheDuke

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

joyously avatar Mar 04 '24 15:03 joyously

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.

martinvonz avatar Mar 04 '24 15:03 martinvonz

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

joyously avatar Mar 04 '24 16:03 joyously

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

No

martinvonz avatar Mar 04 '24 17:03 martinvonz

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.

PhilipMetzger avatar Mar 04 '24 17:03 PhilipMetzger

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

farnoy avatar Mar 08 '24 16:03 farnoy

What compounded my confusion is that the documentation is outdated:

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

martinvonz avatar Mar 08 '24 17:03 martinvonz

+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 avatar Aug 20 '24 21:08 dbarnett