Skip to content

Commit 2f54fb7

Browse files
committed
Optionally use --changed-since for package selection
1 parent ff6eae9 commit 2f54fb7

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/cli.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub struct PackageSelectOptions {
6767
/// and attempts to identify the packages and its dependents through that mechanism. You
6868
/// can use any `tag`, `branch` or `commit`, but you must be sure it is available
6969
/// (and up to date) locally.
70-
#[structopt(short, long)]
71-
pub changed_since: String,
70+
#[structopt(short, long, name = "git-ref")]
71+
pub changed_since: Option<String>,
7272
}
7373

7474
#[derive(StructOpt, Debug)]
@@ -366,24 +366,15 @@ fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<
366366
.into(),
367367
);
368368
}
369-
if changed_since.len() != 0 {
369+
if changed_since.as_ref().map_or(false, |git_ref| !git_ref.is_empty()) {
370370
return Err(
371371
"-p/--packages is mutually exlusive to using -c/--changed-since"
372372
.into(),
373373
);
374374
}
375375
}
376376

377-
let publish = move |p: &Package| {
378-
// If publish is set to false or any registry, it is ignored by default
379-
// unless overriden.
380-
let value = ignore_publish || p.publish().is_none();
381-
382-
trace!("{:}.publish={}", p.name(), value);
383-
value
384-
};
385-
386-
if changed_since.len() != 0 {
377+
if changed_since.as_ref().map_or(false, |git_ref| !git_ref.is_empty()) {
387378
if !skip.is_empty() || !ignore_pre_version.is_empty() {
388379
return Err(
389380
"-c/--changed-since is mutually exlusive to using -s/--skip and -i/--ignore-version-pre"
@@ -393,9 +384,29 @@ fn make_pkg_predicate(ws: &Workspace<'_>, args: PackageSelectOptions) -> Result<
393384

394385
}
395386

396-
let changed = util::changed_packages(ws, &changed_since)?;
397-
if changed.len() == 0 {
398-
return Err("No changes detected".into())
387+
// Either use explicitly given --packages or calculate packages that were
388+
// --changed-since a given Git reference.
389+
let packages = match changed_since {
390+
Some(git_ref) if !git_ref.is_empty() => {
391+
let changed = util::changed_packages(ws, &git_ref)?;
392+
393+
if changed.len() == 0 {
394+
return Err("No changes detected".into())
395+
};
396+
397+
changed.iter().map(Package::name).collect()
398+
}
399+
_ => packages,
400+
};
401+
402+
403+
let publish = move |p: &Package| {
404+
// If publish is set to false or any registry, it is ignored by default
405+
// unless overriden.
406+
let value = ignore_publish || p.publish().is_none();
407+
408+
trace!("{:}.publish={}", p.name(), value);
409+
value
399410
};
400411

401412
if !packages.is_empty() {

0 commit comments

Comments
 (0)