Skip to content

Commit

Permalink
feat: Add rev parse --reference.
Browse files Browse the repository at this point in the history
It's similar to `git rev-parse --symbolic-full-name`.
  • Loading branch information
Byron committed Dec 18, 2023
1 parent 3fba5b8 commit 193ffcd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gitoxide-core/src/repository/revision/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Options {
pub cat_file: bool,
pub tree_mode: TreeMode,
pub blob_format: BlobFormat,
pub show_reference: bool,
}

pub enum TreeMode {
Expand Down Expand Up @@ -46,6 +47,7 @@ pub(crate) mod function {
cat_file,
tree_mode,
blob_format,
show_reference,
}: Options,
) -> anyhow::Result<()> {
repo.object_cache_size_if_unset(1024 * 1024);
Expand Down Expand Up @@ -77,6 +79,12 @@ pub(crate) mod function {
if cat_file {
return display_object(&repo, spec, tree_mode, cache.as_mut().map(|c| (blob_format, c)), out);
}
if let Some(r) = spec.first_reference().filter(|_| show_reference) {
writeln!(out, "{}", r.name)?;
}
if let Some(r) = spec.second_reference().filter(|_| show_reference) {
writeln!(out, "{}", r.name)?;
}
writeln!(out, "{spec}", spec = spec.detach())?;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ pub fn main() -> Result<()> {
explain,
cat_file,
tree_mode,
reference,
blob_format,
} => prepare_and_run(
"revision-parse",
Expand All @@ -947,6 +948,7 @@ pub fn main() -> Result<()> {
format,
explain,
cat_file,
show_reference: reference,
tree_mode: match tree_mode {
revision::resolve::TreeMode::Raw => core::repository::revision::resolve::TreeMode::Raw,
revision::resolve::TreeMode::Pretty => {
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ pub mod revision {
/// Equivalent to the `explain` subcommand.
#[clap(short = 'e', long)]
explain: bool,
/// Also show the name of the reference which led to the object.
#[clap(short = 'r', long, conflicts_with = "explain")]
reference: bool,
/// Show the first resulting object similar to how `git cat-file` would, but don't show the resolved spec.
#[clap(short = 'c', long, conflicts_with = "explain")]
cat_file: bool,
Expand Down

0 comments on commit 193ffcd

Please sign in to comment.