Skip to content

Commit 61f5a4f

Browse files
Nemo157jyn514
authored andcommitted
Add flag to set the last-seen-reference to current HEAD
1 parent ed3255e commit 61f5a4f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/bin/cratesfyi.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,16 @@ enum QueueSubcommand {
216216
/// Get the registry watcher's last seen reference
217217
GetLastSeenReference,
218218

219-
/// Set the register watcher's last seen reference
219+
/// Set the registry watcher's last seen reference
220+
#[command(arg_required_else_help(true))]
220221
SetLastSeenReference {
221-
reference: crates_index_diff::gix::ObjectId,
222+
/// The reference to set to, required unless flag used
223+
#[arg(conflicts_with("head"))]
224+
reference: Option<crates_index_diff::gix::ObjectId>,
225+
226+
/// Fetch the current HEAD of the remote index and use it
227+
#[arg(long, conflicts_with("reference"))]
228+
head: bool,
222229
},
223230
}
224231

@@ -244,8 +251,19 @@ impl QueueSubcommand {
244251
}
245252
}
246253

247-
Self::SetLastSeenReference { reference } => {
254+
Self::SetLastSeenReference { reference, head } => {
255+
let reference = match (reference, head) {
256+
(Some(reference), false) => reference,
257+
(None, true) => {
258+
println!("Fetching changes to set reference to HEAD");
259+
let (_, oid) = ctx.index()?.diff()?.peek_changes()?;
260+
oid
261+
}
262+
(_, _) => unreachable!(),
263+
};
264+
248265
ctx.build_queue()?.set_last_seen_reference(reference)?;
266+
println!("Set last seen reference: {reference}");
249267
}
250268

251269
Self::DefaultPriority { subcommand } => subcommand.handle_args(ctx)?,

src/index/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Index {
7373
})
7474
}
7575

76-
pub(crate) fn diff(&self) -> Result<crates_index_diff::Index> {
76+
pub fn diff(&self) -> Result<crates_index_diff::Index> {
7777
let options = self
7878
.repository_url
7979
.clone()

0 commit comments

Comments
 (0)