Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Clone can't checkout commit pointed to by tag, but Git works #574

@mitchellh

Description

@mitchellh

If a tag is created pointing to a commit that hasn't been pushed yet, then the checkout will error. However, git works, and the commit is browse-able on GitHub. However, you can see its not in the commit history at all.

The only reason this feels like a bug to me is really because git show <tag> and git checkout <tag> somehow work despite the commit not being easily viewable in any other way.

I created a test repository to reproduce this: https://github.com/mitchellh/go-git-test-failure

Notice the tag v0.1.0 points to a commit (you can click it and see it), but if you go to the commit history it doesn't exist, and there are no other branches either. This is a lightweight tag. But clone the repository manually and you'll be able to use that tag with git.

And some code you can run with go run to reproduce this:

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/plumbing"
)

func main() {
	// Create the temporary directory for cloning
	dir, err := ioutil.TempDir("", "test")
	if err != nil {
		panic(err)
	}

	// Clone it into the target directory getting only the tag commit
	repo, err := git.PlainClone(dir, false, &git.CloneOptions{
		URL: "https://github.com/mitchellh/go-git-test-failure.git",
	})
	if err != nil {
		os.RemoveAll(dir)
		panic(err)
	}

	// Get the working tree so we can change refs
	tree, err := repo.Worktree()
	if err != nil {
		panic(err)
	}

	tagName := "v0.1.0"

	// Checkout our tag
	err = tree.Checkout(&git.CheckoutOptions{
		Branch: plumbing.ReferenceName("refs/tags/" + tagName),
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(dir)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions