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

git checkout in colocated repo may abandon old HEAD #1042

Closed
yuja opened this issue Jan 15, 2023 · 0 comments
Closed

git checkout in colocated repo may abandon old HEAD #1042

yuja opened this issue Jan 15, 2023 · 0 comments

Comments

@yuja
Copy link
Collaborator

yuja commented Jan 15, 2023

Description

In colocated repo, if you run jj after git checkout (not jj checkout), old HEAD could be abandoned.
This behavior is correct since the HEAD ref is moved externally, and the old HEAD is no longer referenced by git, but it's easy to lose commits by mistake.

I sometimes do git fetch && git checkout FETCH_HEAD as sloppy way of switching branches, and notice my wip commits went away after that.

Steps to Reproduce the Problem

set -e
set -x

#rm -Rf repo
mkdir repo
cd repo

git init
jj init --git-repo .

touch a
jj ci -m 'jj a'

touch b
jj ci -m 'jj b'

jj log --no-pager

# move HEAD ref back without using jj: 'b' -> 'a'
git checkout `jj log -r 'description("jj a")' -T 'commit_id' --no-graph`

# git::import_refs() abandons old HEAD 'b'
sleep 1
jj log --no-pager

Specifications

yuja added a commit to yuja/jj that referenced this issue May 10, 2023
I'm going to change the behavior of _without_ref() case to mitigate martinvonz#1042.
yuja added a commit to yuja/jj that referenced this issue May 10, 2023
The current behavior was introduced by 20eb9ec "git: don't abandon
HEAD commit when it loses a branch." While the change made HEAD mutation
behavior more consistent with a plain ref operation, HEAD can also move on
checkout, and checkout shouldn't be considered a history rewriting operation.

I'm not saying the new behavior is always correct, but I think it's safer
than losing old HEAD branch. I also think this change will help if we want
to extract HEAD management function from git::import_refs().

Fixes martinvonz#1042.
yuja added a commit that referenced this issue May 11, 2023
I'm going to change the behavior of _without_ref() case to mitigate #1042.
@yuja yuja closed this as completed in 92cfffd May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants