Skip to content

Commit 4ec98b3

Browse files
committed
resolve git, better erroring
1 parent a17b9fc commit 4ec98b3

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<
397397

398398
}
399399

400-
let changed = util::changed_packages(ws, &changed_since);
400+
let changed = util::changed_packages(ws, &changed_since)?;
401401
if changed.len() == 0 {
402402
return Err("No changes detected".into())
403403
};

src/util.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cargo::{
33
util::interning::InternedString,
44
sources::PathSource,
55
};
6-
use log::warn;
6+
use log::{warn, trace};
77
use std::{
88
collections::{HashSet, HashMap},
99
error::Error, fs,
@@ -60,23 +60,29 @@ where
6060
(graph, map)
6161
}
6262

63-
pub fn changed_packages<'a>(ws: &'a Workspace, reference: &str) -> HashSet<Package> {
63+
pub fn changed_packages<'a>(ws: &'a Workspace, reference: &str) -> Result<HashSet<Package>, String> {
64+
65+
ws.config()
66+
.shell()
67+
.status("Calculating", format!("git diff since {:}", reference))
68+
.expect("Writing to Shell doesn't fail");
69+
6470
let path = ws.root();
65-
println!("{:?}", path);
66-
let repo = Repository::open(&path).expect("Workspace isn't a git repo");
71+
let repo = Repository::open(&path)
72+
.map_err(|e| format!("Workspace isn't a git repo: {:?}", e))?;
6773
let current_head = repo.head()
6874
.and_then(|b| b.peel_to_commit())
6975
.and_then(|c| c.tree())
70-
.expect("Could not determine current git HEAD");
76+
.map_err(|e| format!("Could not determine current git HEAD: {:?}", e))?;
7177
let main = repo
72-
.find_reference(reference)
78+
.resolve_reference_from_short_name(reference)
7379
.and_then(|d| d.peel_to_commit())
7480
.and_then(|c| c.tree())
75-
.expect("Reference not found in git repository");
81+
.map_err(|e| format!("Reference not found in git repository: {:?}", e))?;
7682

7783
let diff = repo
7884
.diff_tree_to_tree(Some(&current_head), Some(&main), None)
79-
.expect("Diffing failed");
85+
.map_err(|e| format!("Diffing failed: {:?}", e))?;
8086

8187
let files = diff
8288
.deltas()
@@ -85,6 +91,8 @@ pub fn changed_packages<'a>(ws: &'a Workspace, reference: &str) -> HashSet<Packa
8591
.map(|l| path.join(l))
8692
.collect::<Vec<_>>();
8793

94+
trace!("Files changed since: {:#?}", files);
95+
8896
let mut packages = HashSet::new();
8997

9098
for m in members_deep(ws) {
@@ -97,7 +105,7 @@ pub fn changed_packages<'a>(ws: &'a Workspace, reference: &str) -> HashSet<Packa
97105
}
98106
}
99107

100-
packages
108+
Ok(packages)
101109
}
102110

103111
// Find all members of the workspace, into the total depth

0 commit comments

Comments
 (0)