-
-
Notifications
You must be signed in to change notification settings - Fork 477
Add a revision option to gix clone #2563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,17 @@ impl PrepareFetch { | |
| self.ref_name = name.map(TryInto::try_into).transpose()?.map(ToOwned::to_owned); | ||
| Ok(self) | ||
| } | ||
|
|
||
| /// Set the revision to check out after fetching. | ||
| /// | ||
| /// If `None`, the `HEAD` will be used, which is the default. | ||
| pub fn with_revision<T>(mut self, revision: Option<T>) -> Self | ||
| where | ||
| T: Into<BString>, | ||
| { | ||
| self.revision = revision.map(Into::into); | ||
| self | ||
| } | ||
| } | ||
|
Comment on lines
+64
to
74
|
||
|
|
||
| /// Consumption | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,12 @@ pub enum Error { | |
| RefMap(#[from] crate::remote::ref_map::Error), | ||
| #[error(transparent)] | ||
| ReferenceName(#[from] gix_validate::reference::name::Error), | ||
| #[cfg(feature = "revision")] | ||
| #[error(transparent)] | ||
| RevisionResolve(#[from] crate::revision::spec::parse::single::Error), | ||
| #[cfg(feature = "revision")] | ||
| #[error(transparent)] | ||
| RevisionParse(#[from] gix_error::Error), | ||
| } | ||
|
|
||
| /// Modification | ||
|
|
@@ -300,6 +306,24 @@ impl PrepareFetch { | |
| self.ref_name.as_ref(), | ||
| )?; | ||
|
|
||
| #[cfg(feature = "revision")] | ||
| if let Some(rev) = &self.revision { | ||
| let id = repo.rev_parse_single(rev.as_bstr())?; | ||
| repo.edit_reference(gix_ref::transaction::RefEdit { | ||
|
Comment on lines
+310
to
+312
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| change: gix_ref::transaction::Change::Update { | ||
| log: gix_ref::transaction::LogChange { | ||
| mode: gix_ref::transaction::RefLog::AndReference, | ||
| force_create_reflog: false, | ||
| message: reflog_message.clone(), | ||
| }, | ||
| expected: gix_ref::transaction::PreviousValue::Any, | ||
| new: gix_ref::Target::Object(id.detach()), | ||
| }, | ||
| name: "HEAD".try_into().expect("valid"), | ||
| deref: false, | ||
| })?; | ||
| } | ||
|
Comment on lines
+309
to
+325
|
||
|
|
||
| Ok((self.repo.take().expect("still present"), outcome)) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,10 +212,24 @@ pub(super) fn find_custom_refname<'a>( | |
| wanted: ref_name.clone(), | ||
| }), | ||
| 1 => { | ||
| let item = filtered_items[res.mappings[0] | ||
| .item_index | ||
| .expect("we map by name only and have no object-id in refspec")]; | ||
| Ok((Some(item.target), Some(item.full_ref_name))) | ||
| let mapping = &res.mappings[0]; | ||
| match (mapping.item_index, &mapping.lhs) { | ||
| (Some(idx), _) => { | ||
| let item = filtered_items[idx]; | ||
| Ok((Some(item.target), Some(item.full_ref_name))) | ||
| } | ||
| (None, gix_refspec::match_group::SourceRef::ObjectId(id)) => { | ||
| let target = ref_map | ||
| .mappings | ||
| .iter() | ||
| .find_map(|m| m.remote.as_id().filter(|remote_id| *remote_id == *id)) | ||
| .expect("if it matched, it must be in the mappings"); | ||
| Ok((Some(target), None)) | ||
|
Comment on lines
+221
to
+227
|
||
| } | ||
| (None, gix_refspec::match_group::SourceRef::FullName(_)) => { | ||
| unreachable!("only object ids have no item index") | ||
| } | ||
| } | ||
| } | ||
| _ => Err(Error::RefNameAmbiguous { | ||
| wanted: ref_name.clone(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -679,6 +679,7 @@ pub mod fetch { | |||||
| pub mod clone { | ||||||
| use std::{ffi::OsString, num::NonZeroU32, path::PathBuf}; | ||||||
|
|
||||||
| use gix::bstr::BString; | ||||||
| use gix::remote::fetch::Shallow; | ||||||
|
|
||||||
| #[derive(Debug, clap::Parser)] | ||||||
|
|
@@ -705,6 +706,13 @@ pub mod clone { | |||||
| #[clap(long = "ref", value_parser = crate::shared::AsPartialRefName, value_name = "REF_NAME")] | ||||||
| pub ref_name: Option<gix::refs::PartialName>, | ||||||
|
|
||||||
| /// The revision to check out after cloning. | ||||||
| /// | ||||||
| /// This is useful if you want to clone a specific commit that is not a branch tip. | ||||||
| /// It will fetch the default branch and then attempt to check out this revision. | ||||||
|
||||||
| /// It will fetch the default branch and then attempt to check out this revision. | |
| /// It will perform a normal clone/fetch and then attempt to check out this revision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_revision()is always available, but the actual resolution logic is#[cfg(feature = "revision")]in the fetch implementation. In builds withdefault-features = falsewhererevisionis disabled, this setter becomes a silent no-op. Consider gating the method/field behind the same feature, or documenting/returning an error when the feature isn’t enabled to avoid surprising API behavior.