Skip to content

Commit c7af04d

Browse files
authored
Merge pull request #2073 from cruessler/add-tag-list
feat: add first debug version of `gix tag list`
2 parents 5335c84 + 750ae9b commit c7af04d

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

gitoxide-core/src/repository/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod remote;
4444
pub mod revision;
4545
pub mod status;
4646
pub mod submodule;
47+
pub mod tag;
4748
pub mod tree;
4849
pub mod verify;
4950
pub mod worktree;

gitoxide-core/src/repository/tag.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write) -> anyhow::Result<()> {
2+
let platform = repo.references()?;
3+
4+
for mut reference in platform.tags()?.flatten() {
5+
let tag = reference.peel_to_tag();
6+
let tag_ref = tag.as_ref().map(gix::Tag::decode);
7+
8+
// `name` is the name of the file in `refs/tags/`.
9+
// This applies to both lightweight and annotated tags.
10+
let name = reference.name().shorten();
11+
let mut fields = Vec::new();
12+
match tag_ref {
13+
Ok(Ok(tag_ref)) => {
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());
22+
}
23+
24+
writeln!(out, "{name} [{fields}]", fields = fields.join(", "))?;
25+
}
26+
_ => {
27+
writeln!(out, "{name}")?;
28+
}
29+
}
30+
}
31+
32+
Ok(())
33+
}

src/plumbing/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
plumbing::{
1818
options::{
1919
attributes, commit, commitgraph, config, credential, exclude, free, fsck, index, mailmap, merge, odb,
20-
revision, tree, Args, Subcommands,
20+
revision, tag, tree, Args, Subcommands,
2121
},
2222
show_progress,
2323
},
@@ -1304,6 +1304,17 @@ pub fn main() -> Result<()> {
13041304
},
13051305
),
13061306
},
1307+
Subcommands::Tag(platform) => match platform.cmds {
1308+
Some(tag::Subcommands::List) | None => prepare_and_run(
1309+
"tag-list",
1310+
trace,
1311+
auto_verbose,
1312+
progress,
1313+
progress_keep_open,
1314+
None,
1315+
move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out),
1316+
),
1317+
},
13071318
Subcommands::Tree(cmd) => match cmd {
13081319
tree::Subcommands::Entries {
13091320
treeish,

src/plumbing/options/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub enum Subcommands {
100100
/// Interact with commit objects.
101101
#[clap(subcommand)]
102102
Commit(commit::Subcommands),
103+
/// Interact with tag objects.
104+
#[clap(visible_alias = "tags")]
105+
Tag(tag::Platform),
103106
/// Verify the integrity of the entire repository
104107
Verify {
105108
#[clap(flatten)]
@@ -928,6 +931,20 @@ pub mod commit {
928931
}
929932
}
930933

934+
pub mod tag {
935+
#[derive(Debug, clap::Parser)]
936+
pub struct Platform {
937+
#[clap(subcommand)]
938+
pub cmds: Option<Subcommands>,
939+
}
940+
941+
#[derive(Debug, clap::Subcommand)]
942+
pub enum Subcommands {
943+
/// List all tags.
944+
List,
945+
}
946+
}
947+
931948
pub mod credential {
932949
#[derive(Debug, clap::Subcommand)]
933950
pub enum Subcommands {

0 commit comments

Comments
 (0)