Skip to content

Add tag subcommand#96

Open
SandrineP wants to merge 2 commits intoQuantStack:mainfrom
SandrineP:tag_cmd
Open

Add tag subcommand#96
SandrineP wants to merge 2 commits intoQuantStack:mainfrom
SandrineP:tag_cmd

Conversation

@SandrineP
Copy link
Collaborator

@SandrineP SandrineP commented Feb 10, 2026

Fix #64
Add tag subcommand.

@SandrineP SandrineP marked this pull request as ready for review February 10, 2026 17:01
@SandrineP SandrineP added the enhancement New feature or request label Feb 10, 2026
Copy link
Member

@ianthomas23 ianthomas23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git tag -l v* definitely won't work in the wasm build. so I'll need to support that soon.

{
return;
}
if (pos < message.length() && pos + 1 < message.length())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pos + 1 < message.length() is true then pos < message.length() must also be so it is not necessary to check both.

}

// Tag listing: Print individual message lines
void print_list_lines(const std::string& message, int num_lines)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks quite complicated for a relatively simple task. Maybe a better approach would be to first split the string at newline characters into a vector of strings and walk that vector. There is already a split-string-at-newlines function at

void terminal_pager::split_input_at_newlines(std::string_view str)

which could be pulled out of that file and reused.

But that could be in a later separate PR.

std::string pattern = m_tag_name.empty() ? "*" : m_tag_name;
auto tag_names = repo.tag_list_match(pattern);

for (size_t i = 0; i < tag_names.size(); i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could avoid the loop variable here by using a range-based for loop like this instead:

for (const auto& tag_name: tag_names)
{
    each_tag(repo, tag_name, m_num_lines);
}

throw_if_error(git_tag_list_match(&tag_names, pattern.c_str(), *this));

std::vector<std::string> result;
for (size_t i = 0; i < tag_names.count; ++i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a range-based for loop here too.

throw git_exception("tag '" + m_tag_name + "' already exists", git2cpp_error_code::FILESYSTEM_ERROR);
}
throw git_exception("Unable to create annotated tag", error);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has a lot in common with create_lightweight_tag, maybe it would be worth extracting the common parts in small functions and have the create_XXX_tag be simple "drivers".

throw git_exception("Tag name required", git2cpp_error_code::GENERIC_ERROR);
}

if (m_message.empty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is already tested before calling create_tag, so this check can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the tag command

3 participants