Skip to content

Commit 193ffcd

Browse files
committed
feat: Add rev parse --reference.
It's similar to `git rev-parse --symbolic-full-name`.
1 parent 3fba5b8 commit 193ffcd

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

gitoxide-core/src/repository/revision/resolve.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub struct Options {
66
pub cat_file: bool,
77
pub tree_mode: TreeMode,
88
pub blob_format: BlobFormat,
9+
pub show_reference: bool,
910
}
1011

1112
pub enum TreeMode {
@@ -46,6 +47,7 @@ pub(crate) mod function {
4647
cat_file,
4748
tree_mode,
4849
blob_format,
50+
show_reference,
4951
}: Options,
5052
) -> anyhow::Result<()> {
5153
repo.object_cache_size_if_unset(1024 * 1024);
@@ -77,6 +79,12 @@ pub(crate) mod function {
7779
if cat_file {
7880
return display_object(&repo, spec, tree_mode, cache.as_mut().map(|c| (blob_format, c)), out);
7981
}
82+
if let Some(r) = spec.first_reference().filter(|_| show_reference) {
83+
writeln!(out, "{}", r.name)?;
84+
}
85+
if let Some(r) = spec.second_reference().filter(|_| show_reference) {
86+
writeln!(out, "{}", r.name)?;
87+
}
8088
writeln!(out, "{spec}", spec = spec.detach())?;
8189
}
8290
}

src/plumbing/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ pub fn main() -> Result<()> {
930930
explain,
931931
cat_file,
932932
tree_mode,
933+
reference,
933934
blob_format,
934935
} => prepare_and_run(
935936
"revision-parse",
@@ -947,6 +948,7 @@ pub fn main() -> Result<()> {
947948
format,
948949
explain,
949950
cat_file,
951+
show_reference: reference,
950952
tree_mode: match tree_mode {
951953
revision::resolve::TreeMode::Raw => core::repository::revision::resolve::TreeMode::Raw,
952954
revision::resolve::TreeMode::Pretty => {

src/plumbing/options/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ pub mod revision {
655655
/// Equivalent to the `explain` subcommand.
656656
#[clap(short = 'e', long)]
657657
explain: bool,
658+
/// Also show the name of the reference which led to the object.
659+
#[clap(short = 'r', long, conflicts_with = "explain")]
660+
reference: bool,
658661
/// Show the first resulting object similar to how `git cat-file` would, but don't show the resolved spec.
659662
#[clap(short = 'c', long, conflicts_with = "explain")]
660663
cat_file: bool,

0 commit comments

Comments
 (0)