Skip to content

Commit e0bfdae

Browse files
committed
feat(update): working on next release
♬ DJ Pony Feat. Swingrowers - Buonasera Signorina (Original)
1 parent 71a9837 commit e0bfdae

2 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎src/tools/diff_analysis.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ fn run_diff(
5656
let repo = Repository::open(repo_path.unwrap_or("."))?;
5757

5858
let base_commit = if let Some(b) = base {
59-
let obj = repo.revparse_single(b)?;
60-
obj.peel_to_commit()?
59+
let obj = repo
60+
.revparse_single(b)
61+
.map_err(|e| format!("revspec '{b}' not found: {e}"))?;
62+
obj.peel_to_commit()
63+
.map_err(|e| format!("revspec '{b}' not found: {e}"))?
6164
} else {
6265
repo.head()?.peel_to_commit()?
6366
};
6467

6568
// The head revspec must resolve even though the diff is taken against the
6669
// working tree. Dropping this check made an unresolvable head succeed with an
6770
// empty result, which is the failure mode this file is meant to avoid.
68-
repo.revparse_single(head)?.peel_to_commit()?;
71+
repo.revparse_single(head)
72+
.map_err(|e| format!("revspec '{head}' not found: {e}"))?
73+
.peel_to_commit()
74+
.map_err(|e| format!("revspec '{head}' not found: {e}"))?;
6975

7076
let base_tree = base_commit.tree()?;
7177

‎tests/unit/diff_analysis_edge_tests.rs‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,60 @@ fn test_revspec_starting_with_dash_rejected() {
263263
);
264264
}
265265

266+
#[test]
267+
fn test_head_tilde_1_on_single_commit_repo_wraps_error() {
268+
// Reproduces the CI failure: a shallow checkout has no parent for HEAD,
269+
// so revparse_single("HEAD~1") returns a libgit2 error whose raw message
270+
// ("parent 0 does not exist") contains neither "revspec" nor "not found".
271+
// The production wrapper must add that context so callers get a meaningful
272+
// error.
273+
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
274+
let repo_path = temp_dir.path();
275+
276+
Command::new("git")
277+
.args(["init", "-q"])
278+
.current_dir(repo_path)
279+
.output()
280+
.expect("failed to init git repo");
281+
Command::new("git")
282+
.args(["config", "user.email", "test@test.com"])
283+
.current_dir(repo_path)
284+
.output()
285+
.expect("failed to set email");
286+
Command::new("git")
287+
.args(["config", "user.name", "Test"])
288+
.current_dir(repo_path)
289+
.output()
290+
.expect("failed to set name");
291+
292+
std::fs::write(repo_path.join("file.txt"), "content\n").expect("write");
293+
Command::new("git")
294+
.args(["add", "."])
295+
.current_dir(repo_path)
296+
.output()
297+
.expect("failed to add");
298+
Command::new("git")
299+
.args(["commit", "-q", "-m", "only commit"])
300+
.current_dir(repo_path)
301+
.output()
302+
.expect("failed to commit");
303+
304+
let input = DiffAnalysisInput {
305+
file_path: "file.txt".to_string(),
306+
repo_path: Some(repo_path.to_str().unwrap().to_string()),
307+
base_commit: Some("HEAD~1".to_string()),
308+
head_commit: Some("HEAD".to_string()),
309+
};
310+
311+
let result = analyze_diff(input);
312+
assert!(result.is_err(), "HEAD~1 on a single-commit repo must error");
313+
let err = result.unwrap_err().to_string();
314+
assert!(
315+
err.contains("revspec") || err.contains("not found"),
316+
"error should be meaningful, got: {err}"
317+
);
318+
}
319+
266320
#[test]
267321
fn test_valid_range_returns_files() {
268322
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");

0 commit comments

Comments
 (0)