git sparse-checkout, missing branch name associated with the commit from the last tag

171 Views Asked by At

as in the title, I’m using git sparse-checkout, and I’m missing commits between the last git tag and the last commit I’m on. It creates a problem that I will try to describe it in a few points below:

  1. I use git sparse checkout to get only a small part of my repository
  2. I use git fetch origin --tags to fetch all tags to my local repository
  3. I'm trying to get the data required for my script - branches, commits, and tags associated with the commit. Below powershell script I am using to get the data:
& git tag | ForEach-Object {
        $commit = (git rev-list -n 1 $_)
        [PSCustomObject]@{
            tag    = $_
            commit = $commit
            branch = (git branch --contains $commit)
        }
} | ForEach-Object { Write-Host $_ }

Everything looks fine after running this script, except for the last tag, for my last tag I did not receive any linked branches. However, I should receive at least 1 branch (the one I am currently on) Script result:

@{tag=1; commit=0000000000000000000000000000000000000001; branch=System.Object[]}
@{tag=2; commit=0000000000000000000000000000000000000002; branch=System.Object[]}
@{tag=3; commit=0000000000000000000000000000000000000003; branch=}

0000000000000000000000000000000000000001- represents the commit where the tag was created, the same rule for the other 2 tags. Currently I am on commit 0000000000000000000000000000000000000004, which was created from commit 0000000000000000000000000000000000000003 - so the tag, should be the same (tag=3) for both these commits.

The problem only occure with git sparse-checkout, when I clone the whole repo with git clone develop, I am getting all data needed:

Data when git clone were used

@{tag=1; commit=0000000000000000000000000000000000000001; branch=System.Object[]}
@{tag=2; commit=0000000000000000000000000000000000000002; branch=System.Object[]}
@{tag=3; commit=0000000000000000000000000000000000000003; branch=System.Object[]}

2nd example:

Command and result after regular git clone: git branch --contains 0000000000000000000000000000000000000003 returns * develop

Command and result after git sparse: git branch --contains 0000000000000000000000000000000000000003 returns <empty>

Do you have any idea, why I am not getting any branches? What is the diffrence between regular clone and sparse? Any idea how to fix the difference between sparse-checkout and clone?

0

There are 0 best solutions below