Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340836 - Creating a branch from a tag results in bad HEAD
Summary: Creating a branch from a tag results in bad HEAD
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: Other Linux
: P3 normal with 2 votes (vote)
Target Milestone: 1.1   Edit
Assignee: Matthias Sohn CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-24 05:31 EDT by Carsten Pfeiffer CLA
Modified: 2011-07-05 08:25 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Pfeiffer CLA 2011-03-24 05:31:46 EDT
Build Identifier: I20100608-0911

When creating a local branch from an existing tag, the refs/heads/newbranch file contains the wrong object (tag instead of commit).

git fsck shows this:
error: HEAD: not a commit
error: refs/heads/newbranch: not a commit

newbranch contains the tag, but it should contain the commit.

Reproducible: Always

Steps to Reproduce:
1. clone http://github.com/unclebob/fitnesse
2. create a local branch with egit and choose refs/tags/20110104 as source branch
3. run git fsck on the clone
Comment 1 Carsten Pfeiffer CLA 2011-03-24 05:34:09 EDT
I'm using the nightly build from 20110323. #336291 shows a similar problem.
Comment 2 Laurent Gauthier CLA 2011-04-07 06:22:06 EDT
I am seeing this same issue on Windows.

Creating a branch from a tag using Egit/Eclipse and then trying to commit some changes later from the command line (msysgit) results in a segmentation fault of git.
Comment 3 Laurent Gauthier CLA 2011-04-08 04:59:33 EDT
I thought I would do a bit analysis on the probable cause of the failure here.

I went through the Egit code on github and here is what I have noticed:

https://github.com/eclipse/egit/blob/master/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchWizard.java

In this Wizard class there are two constructors one using a Commit as the basis for the branch, and the other using a Ref (Tag) as the basis for the branch.

https://github.com/eclipse/egit/blob/master/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java

This is the class from which the Wizard class is created, with the following code:

CreateBranchWizard wiz = new CreateBranchWizard(repo,
						refFromDialog());

The refFromDialog() method is implemented in:

https://github.com/eclipse/egit/blob/master/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/AbstractBranchSelectionDialog.java

The branch created from a Tag is itself created in the createBranch() method of CreateBranchPage class by the following code:

cbop = new CreateLocalBranchOperation(myRepository, newRefName,
			myRepository.getRef(this.branchCombo.getText()),
			upstreamConfig);

If we look at the handling of this in:

https://github.com/eclipse/egit/blob/master/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CreateLocalBranchOperation.java

Here (in the execute method) what we see is that branches created based on tags and branches are processed in the same way. I guess maybe these two paths should be differentiated at least a this stage...

What do you think?
Comment 4 Laurent Gauthier CLA 2011-04-08 09:01:57 EDT
More analysis details...

If from the command line you create two tags in the following ways:

  git tag RELEASE_1.0

and

  git tag -a RELEASE_2.0

The RELEASE_2.0 tag is created as a proper tag object.

Egit will create a perfectly working branch from the RELEASE_1.0 tag, but the branch created from RELEASE_2.0 tag will fail during commit...

So the redux is that the "Create branch from tag" functionality fails if the tag is actually a "tag object".
Comment 5 Jens Reimann CLA 2011-05-17 04:41:53 EDT
This seems still to be an issue with egit 0.12.1. "git branch branchname refs/tags/tagname" from the command line works though.
Comment 6 Sasa Zivkov CLA 2011-07-05 08:25:29 EDT
This was caused by the CreateBranchCommadn in JGit.
JGit bug fix proposed at:
http://egit.eclipse.org/r/#change,3816