Skip to content

Commit 750ae9b

Browse files
committed
refactor
- add alias - support `tags` as alias, invoked without explicit `list` - always put annotated tag information into `[]`, despite being more noisy.
1 parent a845a4b commit 750ae9b

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

gitoxide-core/src/repository/tag.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write) -> anyhow::Result<()> {
22
let platform = repo.references()?;
33

4-
for mut reference in (platform.tags()?).flatten() {
4+
for mut reference in platform.tags()?.flatten() {
55
let tag = reference.peel_to_tag();
66
let tag_ref = tag.as_ref().map(gix::Tag::decode);
77

8-
// `name` is the name of the file in `refs/tags/`. This applies to both lightweight as well
9-
// as annotated tags.
8+
// `name` is the name of the file in `refs/tags/`.
9+
// This applies to both lightweight and annotated tags.
1010
let name = reference.name().shorten();
11-
11+
let mut fields = Vec::new();
1212
match tag_ref {
1313
Ok(Ok(tag_ref)) => {
14-
// `tag_name` is the name provided by the user via `git tag -a/-s/-u`. It is only
15-
// present for annotated tags.
16-
let tag_name = tag_ref.name;
17-
18-
if name == tag_name {
19-
writeln!(out, "{name} *")?;
20-
} else {
21-
writeln!(out, "{name} [tag name: {}]", tag_ref.name)?;
14+
// `tag_name` is the name provided by the user via `git tag -a/-s/-u`.
15+
// It is only present for annotated tags.
16+
fields.push(format!(
17+
"tag name: {}",
18+
if name == tag_ref.name { "*".into() } else { tag_ref.name }
19+
));
20+
if tag_ref.pgp_signature.is_some() {
21+
fields.push("signed".into());
2222
}
23+
24+
writeln!(out, "{name} [{fields}]", fields = fields.join(", "))?;
2325
}
2426
_ => {
2527
writeln!(out, "{name}")?;

src/plumbing/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,8 @@ pub fn main() -> Result<()> {
13041304
},
13051305
),
13061306
},
1307-
Subcommands::Tag(cmd) => match cmd {
1308-
tag::Subcommands::List => prepare_and_run(
1307+
Subcommands::Tag(platform) => match platform.cmds {
1308+
Some(tag::Subcommands::List) | None => prepare_and_run(
13091309
"tag-list",
13101310
trace,
13111311
auto_verbose,

src/plumbing/options/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ pub enum Subcommands {
101101
#[clap(subcommand)]
102102
Commit(commit::Subcommands),
103103
/// Interact with tag objects.
104-
#[clap(subcommand)]
105-
Tag(tag::Subcommands),
104+
#[clap(visible_alias = "tags")]
105+
Tag(tag::Platform),
106106
/// Verify the integrity of the entire repository
107107
Verify {
108108
#[clap(flatten)]
@@ -932,6 +932,12 @@ pub mod commit {
932932
}
933933

934934
pub mod tag {
935+
#[derive(Debug, clap::Parser)]
936+
pub struct Platform {
937+
#[clap(subcommand)]
938+
pub cmds: Option<Subcommands>,
939+
}
940+
935941
#[derive(Debug, clap::Subcommand)]
936942
pub enum Subcommands {
937943
/// List all tags.

0 commit comments

Comments
 (0)