Skip to content

Commit d40197f

Browse files
committed
cli: annotate: do not panic on reaching initial commit.
As described in jj-vcs#5909, in the case where jj was initialized in a shallowly cloned repository which was then unshallow'd, jj does not import the fetched commits that were outside the shallow boundary. However, it does import the ones after the boundary, which after unshallowing do not contain the changes made before the boundary. Therefore, when running annotate in such a case, jj would panic because it does not find the commit from which a line originates. This simply sets the empty commit as carrying the blame for that line.
1 parent 1602824 commit d40197f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4545

4646
### Fixed bugs
4747

48+
* When jj is used with a repository that was shallowly cloned, and then filled
49+
up with `git fetch --unshallow`, do not panic on git annotate anymore.
50+
4851
## [0.27.0] - 2025-03-05
4952

5053
### Release highlights

cli/src/commands/file/annotate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use clap_complete::ArgValueCandidates;
1616
use clap_complete::ArgValueCompleter;
1717
use jj_lib::annotate::get_annotation_for_file;
1818
use jj_lib::annotate::FileAnnotation;
19+
use jj_lib::backend::CommitId;
1920
use jj_lib::repo::Repo;
2021
use jj_lib::revset::RevsetExpression;
2122
use tracing::instrument;
@@ -124,8 +125,9 @@ fn render_file_annotation(
124125
ui.request_pager();
125126
let mut formatter = ui.stdout_formatter();
126127
let mut last_id = None;
128+
let default_id = CommitId::from_hex("0000000000000000000000000000000000000000");
127129
for (line_number, (commit_id, content)) in annotation.lines().enumerate() {
128-
let commit_id = commit_id.expect("should reached to the empty ancestor");
130+
let commit_id = commit_id.unwrap_or(&default_id);
129131
let commit = repo.store().get_commit(commit_id)?;
130132
let first_line_in_hunk = last_id != Some(commit_id);
131133
let annotation_line = AnnotationLine {

0 commit comments

Comments
 (0)