Skip to content

Commit

Permalink
fix(monorepo): allow diffing orphan commits
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Jan 23, 2023
1 parent 64df65b commit 02a1c5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/git/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::git::status::Statuses;
use colored::Colorize;
use git2::Error;
use git2::{Error, Oid};
use serde::de::StdError;
use std::fmt::{Display, Formatter};
use std::{fmt, io};
Expand Down
20 changes: 12 additions & 8 deletions src/git/revspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,20 @@ impl Repository {
let mut commits = vec![];
let package = SETTINGS.packages.get(package).expect("package exists");
for commit in commit_range.commits {
let parent = commit.parent(0)?.id().to_string();
let t1 = self
.tree_to_treeish(Some(&parent))?
.expect("Failed to get parent tree");
let parent = commit.parent(0).ok()
.map(|commit| commit.id().to_string());

let t2 = self
let parent_tree = self.tree_to_treeish(parent.as_ref())?;


let current_tree = self
.tree_to_treeish(Some(&commit.id().to_string()))?
.expect("Failed to get commit tree");

let diff = self.0.diff_tree_to_tree(t1.as_tree(), t2.as_tree(), None)?;
let diff = match parent_tree {
None => self.0.diff_tree_to_tree(None, current_tree.as_tree(), None)?,
Some(tree) => self.0.diff_tree_to_tree(tree.as_tree(), current_tree.as_tree(), None)?,
};

for delta in diff.deltas() {
if let Some(old) = delta.old_file().path() {
Expand Down Expand Up @@ -723,7 +727,7 @@ mod test {
git commit --allow-empty -q -m $message;
git log --format=%H -n 1;
)
.map_err(|e| anyhow!(e))
.map_err(|e| anyhow!(e))
};

run_cmd!(
Expand Down Expand Up @@ -767,7 +771,7 @@ mod test {
git commit --allow-empty -q -m $message;
git log --format=%H -n 1;
)
.map_err(|e| anyhow!(e))
.map_err(|e| anyhow!(e))
};

run_cmd!(
Expand Down

0 comments on commit 02a1c5a

Please sign in to comment.