Skip to content

fix: Fix crash when current head no longer exists#186

Closed
dotdash wants to merge 1 commit into
Cretezy:mainfrom
blazingjj:fix_crash_on_missing_head
Closed

fix: Fix crash when current head no longer exists#186
dotdash wants to merge 1 commit into
Cretezy:mainfrom
blazingjj:fix_crash_on_missing_head

Conversation

@dotdash

@dotdash dotdash commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator

When e.g. issuing a jj new command in a different window that causes the current head to disappear (because it was empty), we currently crash when trying to find the latest version of that head. Instead, we should just switch to the @ revision in that case.

When e.g. issuing a `jj new` command in a different window that causes
the current head to disappear (because it was empty), we currently crash
when trying to find the latest version of that head. Instead, we should
just switch to the `@` revision in that case.
@DemvSteinbrink
DemvSteinbrink force-pushed the fix_crash_on_missing_head branch from 2360c33 to 6bd9456 Compare November 25, 2025 08:51
Comment thread src/ui/files_tab.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think self.set_head(..) will set current head, refresh files, and refresh diff. Why not call self.set_head in both cases? This would lead to a simpler solution (warning! not tested with compiler)

let next_head = commander.get_head_latest(&self.head)
  .or_else(|_| commander.get_current_head())?;
self.set_head(commander, next_head);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was something that I thought made this necessary, but neither did I document it, nor can I recall it, and @Edgpaez's fix seems to work just fine. And we likely can't merge this PR anyway due to having no reviewers 🤷🏻

@Edgpaez

Edgpaez commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

This also crashes when doing a fetch that removes the current head (for instance because you were in a branch that is merged).

I took a look and I think this is caused by #181
The problem is that jj log --no-graph -r luwt fails if luwt does not exists. However, after #181 we do jj log --no-graph -r 'change_id(luwt)' that simply returns empty if luwt does not exists.

That fixes the crash but doesn't update the UI to show the new change. For that, we also need to do self.set_head as proposed by @peso

I implemented this in #188 that fixes this in both log_tab and files_tab 👍

@dotdash dotdash closed this Dec 7, 2025
@DemvSteinbrink
DemvSteinbrink deleted the fix_crash_on_missing_head branch December 24, 2025 12:43
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

Successfully merging this pull request may close these issues.

3 participants