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

Weird corner-case issue with .gitignore in git init'ed repos #4222

Closed
juanmeleiro opened this issue Aug 5, 2024 · 4 comments
Closed

Weird corner-case issue with .gitignore in git init'ed repos #4222

juanmeleiro opened this issue Aug 5, 2024 · 4 comments
Labels
🐛bug Something isn't working

Comments

@juanmeleiro
Copy link

Description

So, for context: I keep my ~/.config on version control. It started on git. Just for aesthetic purposes, my .gitignore file for this repo is actually ~/.config/gitignore (note the lack of a dot). This was done using the following command:

git config core.excludesFile gitignore

All was well and good. But also, I didn't like to do cd .config every time, so I aliased as config this command:

git --work-tree=$XDG_CONFIG_HOME --git-dir=$XDG_CONFIG_HOME/.git

All was well and good. And then, I discovered jj and, evidently, made the switch (jj git init --colocate and all that jazz). I changed the alias:

jj --repository $XDG_CONFIG_HOME

And all was well and good, until I did config status, when all hell broke loose. All those large files those anoying applications keep in my beautiful config directory started resurfacing from the depths of the gitignore, jj trying to index them all just to fail because of some megabyte-sized monster. Oh the horrors.

But more than that, I was confused. Weren't they ignored? And jj knows it, as the following works quite well, thank you:

$ cd .config
$ jj status

Steps to Reproduce the Problem

Go to some directory in your system and run the following:

$ mkdir testrepo
$ cd testrepo
$ git config core.excludesFile gitignore
$ jj git init --colocate
$ echo a > gitignore
$ touch a
$ jj status
Working copy changes:
A gitignore
Working copy : ntsqttkw da1a1604 (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
$ cd ..
$ jj --repository testrepo/
Working copy changes:
A testrepo/a
A testrepo/gitignore
Working copy : ntsqttkw 2c759af3 (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)

Expected Behavior

The two outputs of the status subcommand should be the same. The same files should be ignored.

Actual Behavior

They aren't.

Specifications

$ uname -mrsv
Linux 6.6.42-1-lts #2-Alpine SMP PREEMPT_DYNAMIC 2024-07-25 15:20:22 x86_64

Comments

I'm not sure what the fix should be, or even if it should be fixed. Anyway, I'd love suggestions to deal with the situation. Specifically, I would like to be able to

  1. Keep the file as gitignore (without the dot)
  2. Use a command such as jj --repository $XDG_CONFIG_HOME.
  3. Not suffer (from the consequences of the command).
@juanmeleiro juanmeleiro changed the title Weird corner-case issues with .gitignore in git init'ed repos Weird corner-case issue with .gitignore in git init'ed repos Aug 5, 2024
@yuja
Copy link
Contributor

yuja commented Aug 6, 2024

So the issue is that core.excludesFile is resolved relative to cwd in jj, but relative to the worktree root in git?

I assume this will be fixed if we leverage gitoxide function to resolve paths loaded from the git config.

@yuja yuja added the 🐛bug Something isn't working label Aug 6, 2024
@juanmeleiro
Copy link
Author

I guess… I was thinking jj ignores the config when not on the repo directory. But, that makes more sense. Is this something easy enough for me to help with? (No experience in Rust, much experience programming, never looked at the source)

@yuja
Copy link
Contributor

yuja commented Aug 7, 2024

Is this something easy enough for me to help with? (No experience in Rust, much experience programming, never looked at the source)

It wouldn't be hard to fix. We'll probably need to copy core.excludesFile handling bits from gitoxide. The path is currently resolved here:

https://github.com/martinvonz/jj/blob/7bdb28f1fe6e4aebf9b0be9adfe6730d1f24c10a/cli/src/cli_util.rs#L803-L813

(FWIW, I noticed the config API slightly changed in the latest gitoxide version. We might need to upgrade it first.)

@yuja
Copy link
Contributor

yuja commented Aug 7, 2024

need to copy core.excludesFile handling bits from gitoxide

Appears that both git and gix don't resolve relative paths at config layer. The git CLI chdir() to the work tree directory (by setup_work_tree()) first, then reads ignore file at cwd. Maybe we'll need to simulate that by resolving the path relative to the workspace root.

yuja added a commit to yuja/jj that referenced this issue Aug 7, 2024
The "git" command appears to chdir() to the --work-tree directory first, then
read() the core.excludesFile file. There's no manual relative path resolution
in "git".

Fixes jj-vcs#4222
yuja added a commit to yuja/jj that referenced this issue Aug 7, 2024
The "git" command appears to chdir() to the --work-tree directory first, then
read() the core.excludesFile file. There's no manual relative path resolution
in "git".

Fixes jj-vcs#4222
yuja added a commit to yuja/jj that referenced this issue Aug 8, 2024
The "git" command appears to chdir() to the --work-tree directory first, then
read() the core.excludesFile file. There's no manual relative path resolution
in "git".

Fixes jj-vcs#4222
@yuja yuja closed this as completed in 9fb9e73 Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants