Open BatmanAoD opened 1 day ago
Does Git automatically restore a missing .git/HEAD
?
because
jj git export
overwrites HEAD with whatever jj thinks it should be.
That describes the current git::reset_head()
behavior, but it's kinda bug. jj
should update HEAD
only if it matches the internal view.git_head
record. https://github.com/martinvonz/jj/issues/3754
I'm not against adding git fsck
-like command for recovery, but I wouldn't expect jj git export
fixes corrupted repository.
Does Git automatically restore a missing
.git/HEAD
?
No; I mentioned this at the very end of my comment.
Is your feature request related to a problem? Please describe.
In general,
.git/HEAD
should never be missing in a colocated repo. But it can be useful to overwrite it manually, and sometimes people trying to make a manual change make mistakes.If
.git/HEAD
is missing, but the.git
repository is otherwise uncorrupted,jj
has all the information it needs to restore the repository to a working state withjj git export
, becausejj git export
overwritesHEAD
with whateverjj
thinks it should be.This, however, is not what happens:
Describe the solution you'd like In the case where the
.git/HEAD
file is missing, but.jj/
and.git/
exist, I would likejj git export
to restore the last known git-head from the operation log. This would bring the repository back to a usable state.The message above should be modified to indicate that
jj git export
may be able to fix the broken state.Describe alternatives you've considered
jj
has no idea why the file is missing, it has no idea what commit the user would expect to be the currentHEAD
. That said, the repository is completely broken and unusable (by bothgit
andjj
) until.git/HEAD
is restored, so it's hard to see how restoring a somewhat-outdatedHEAD
is any worse..git/HEAD
, and it should be surprising when it's missing. Silently pretending it was never gone would be a pretty strange behavior for, say,jj status
. Even noisily fixing it, i.e. printing a warning and then fixing the repo, seems like something that probably shouldn't happen just from runningjj status
, IMO, much less something that is expected to change the working copy, such asjj new <foo>
..git/HEAD
or corruption in other files.jj git fix
command.jj git export
. However, I was surprised thatjj git export
didn't just write a newHEAD
file in the first place, so if there's a new command, the "Failed to open git repository" error message should at least recommend trying the new command. Additionally, the existence of something likejj git fix
seems...potentially overly ambitious; it could lead people to expect thatjj
can fix more types of corruption than it actually can.Additional context
As far as I can tell, there is no
git
command that will restore.git/HEAD
, even though the reflog should provide the means to do so. I don't know whygit
doesn't provide tools for basic fix-ups.