Skip to content

get branch of commit on detached head #326

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

Merged
merged 5 commits into from
Jan 6, 2015
Merged

Conversation

grufffta
Copy link
Contributor

I've been using gitversion with tfs build and had some issues with building the master branch which I think is related to issue #179 although other branches build correctly.

When the repository is checked out the HEAD points to master. The commit is then checked out to a detached branch. On the develop/feature/release branches the sha commit will be different so GitVersion correctly gets the branch.

If you are building the master branch then 2 branches are found as the HEAD is pointing to the master with the same commit. As we are building a remote branch we should only look for the commit in the tracking branches.

Thanks
Gruff

@JakeGinnivan
Copy link
Contributor

Hey

Don't suppose you could add a test showing this problem and verifying the fix. We are trying to get some improved coverage lately because there are some rather large changes in the works (internally) and we don't want to regress anything.

@grufffta
Copy link
Contributor Author

Hi Jake, I'm going to try to look at this today.
I haven't been able to reproduce by creating a new repository in the test as the issue seems to only occur when tracking branches exist. so I'll create a one on git to use in the test that mimics the behaviour.

@JakeGinnivan
Copy link
Contributor

If you need a hand with the tests, like how to create tracking branches on the fly using libgit2 then i'm sure either myself or @nulltoken could help out.

@grufffta
Copy link
Contributor Author

Hi Jake

I've created a repository here https://github.com/grufffta/GitVersionTest that reproduces the issue for the test. I did have a brief look at using lib2git, but, if you have an example on how to create the tracking branches then I will happily switch it over as that was what was holding me back.

@JakeGinnivan
Copy link
Contributor

Here are some libgit2sharp tests which should give you the components to do this:

https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp.Tests/BranchFixture.cs#L294
https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp.Tests/BranchFixture.cs#L358
https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp.Tests/RemoteFixture.cs#L62

Then the test could look something like:

using (var remote = new EmptyRepositoryFixture(new Config()))
using (var local= new EmptyRepositoryFixture(new Config()))
{
    local.Network.Remotes.Add(remote);
    remote.MakeACommit();

    etc..

Appreciate you looking into this. Also it would be good to use Assert.Throws or Should.Throw rather than [ExpectedException]

I also like the idea of the remote branch fixture. Would be good to create a nice pattern for this sort of test

JakeGinnivan added a commit that referenced this pull request Jan 6, 2015
get branch of commit on detached head
@JakeGinnivan JakeGinnivan merged commit b68ccae into GitTools:master Jan 6, 2015
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.

2 participants