Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Overview

This PR adds branch and tag count information to the repository header section of the git-metrics report. This feature helps users quickly identify whether they're analyzing a full clone with many branches or a single-branch clone, which is particularly useful when comparing repository analyses before and after history rewrites.

Problem

When analyzing multiple clones of the same repository (e.g., before and after a history rewrite), it was difficult to distinguish between:

  • Full clones with thousands of branches
  • Single-branch or shallow clones

This led to surprising results where differences in repository metrics were actually due to different clone configurations rather than actual repository changes.

Solution

Added two new metadata fields to the repository header:

  • Branches: Total count of all branches (local and remote) using git branch -a
  • Tags: Total count of all tags using git tag

Example Output

REPOSITORY #############################################################################################################

Git directory              /home/runner/work/git-metrics/git-metrics/.git
Remote                     https://github.com/steffen/git-metrics
Last modified              Thu, 16 Oct 2025 13:08 UTC
Most recent commit         Thu, 16 Oct 2025 (e82709b)
Branches                   2
Tags                       1
First commit               Sun, 28 Sep 2025 (0f7edd)
Age                        18 days

Implementation Details

  1. Added countNonEmptyLines() helper function: Extracts common line counting logic to reduce code duplication
  2. Added GetBranchCount() function: Counts all branches in the repository
  3. Added GetTagCount() function: Counts all tags in the repository
  4. Updated main.go: Displays branch and tag counts in the repository header section
  5. Added comprehensive tests: Includes edge cases like empty repositories and repositories with no tags

Testing

  • ✅ All existing tests pass
  • ✅ Added new unit tests for branch and tag counting functions
  • ✅ Tested with repositories containing multiple branches and tags
  • ✅ Tested edge case with repositories containing no tags
  • ✅ Verified correct handling of empty git command output

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Print meta info about branches & tags</issue_title>
<issue_description># Feature

In the header on top of the report, print how many branches & tags are there in the repo.

Explanation

I've analyzed a few clones of the same repo, before and after history rewrite, and got surprising results; only later I realized that some of them were full clones with 1000s of branches, while others were single-branch clones.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #103


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add meta info printout for branches and tags Print meta info about branches & tags in repository header Oct 16, 2025
Copilot AI requested a review from steffen October 16, 2025 13:10
Copilot finished work on behalf of steffen October 16, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print meta info about branches & tags

2 participants