Skip to content

feat: add first debug version of gix tag list #2073

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gitoxide-core/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod remote;
pub mod revision;
pub mod status;
pub mod submodule;
pub mod tag;
pub mod tree;
pub mod verify;
pub mod worktree;
Expand Down
31 changes: 31 additions & 0 deletions gitoxide-core/src/repository/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub fn list(repo: gix::Repository, out: &mut dyn std::io::Write) -> anyhow::Result<()> {
let platform = repo.references()?;

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

// `name` is the name of the file in `refs/tags/`. This applies to both lightweight as well
// as annotated tags.
let name = reference.name().shorten();

match tag_ref {
Ok(Ok(tag_ref)) => {
// `tag_name` is the name provided by the user via `git tag -a/-s/-u`. It is only
// present for annotated tags.
let tag_name = tag_ref.name;

if name == tag_name {
writeln!(out, "{name} *")?;
} else {
writeln!(out, "{name} [tag name: {}]", tag_ref.name)?;
}
}
_ => {
writeln!(out, "{name}")?;
}
}
}

Ok(())
}
13 changes: 12 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
plumbing::{
options::{
attributes, commit, commitgraph, config, credential, exclude, free, fsck, index, mailmap, merge, odb,
revision, tree, Args, Subcommands,
revision, tag, tree, Args, Subcommands,
},
show_progress,
},
Expand Down Expand Up @@ -1304,6 +1304,17 @@ pub fn main() -> Result<()> {
},
),
},
Subcommands::Tag(cmd) => match cmd {
tag::Subcommands::List => prepare_and_run(
"tag-list",
trace,
auto_verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::tag::list(repository(Mode::Lenient)?, out),
),
},
Subcommands::Tree(cmd) => match cmd {
tree::Subcommands::Entries {
treeish,
Expand Down
11 changes: 11 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub enum Subcommands {
/// Interact with commit objects.
#[clap(subcommand)]
Commit(commit::Subcommands),
/// Interact with tag objects.
#[clap(subcommand)]
Tag(tag::Subcommands),
/// Verify the integrity of the entire repository
Verify {
#[clap(flatten)]
Expand Down Expand Up @@ -928,6 +931,14 @@ pub mod commit {
}
}

pub mod tag {
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// List all tags.
List,
}
}

pub mod credential {
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
Expand Down
Loading