factor out unmanaged checkout into its own functions
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
parent
94c50fa3a8
commit
5152721ae0
|
@ -184,6 +184,11 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
|
||||||
|
|
||||||
return buildCommit(cc, "refs/heads/"+c.Branch), nil
|
return buildCommit(cc, "refs/heads/"+c.Branch), nil
|
||||||
} else {
|
} else {
|
||||||
|
return c.checkoutUnmanaged(ctx, path, url, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CheckoutBranch) checkoutUnmanaged(ctx context.Context, path, url string, opts *git.AuthOptions) (_ *git.Commit, err error) {
|
||||||
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
|
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
|
||||||
FetchOptions: git2go.FetchOptions{
|
FetchOptions: git2go.FetchOptions{
|
||||||
DownloadTags: git2go.DownloadTagsNone,
|
DownloadTags: git2go.DownloadTagsNone,
|
||||||
|
@ -211,7 +216,6 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
|
||||||
defer cc.Free()
|
defer cc.Free()
|
||||||
return buildCommit(cc, "refs/heads/"+c.Branch), nil
|
return buildCommit(cc, "refs/heads/"+c.Branch), nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type CheckoutTag struct {
|
type CheckoutTag struct {
|
||||||
Tag string
|
Tag string
|
||||||
|
@ -305,6 +309,11 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
|
||||||
defer cc.Free()
|
defer cc.Free()
|
||||||
return buildCommit(cc, "refs/tags/"+c.Tag), nil
|
return buildCommit(cc, "refs/tags/"+c.Tag), nil
|
||||||
} else {
|
} else {
|
||||||
|
return c.checkoutUnmanaged(ctx, path, url, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CheckoutTag) checkoutUnmanaged(ctx context.Context, path, url string, opts *git.AuthOptions) (_ *git.Commit, err error) {
|
||||||
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
|
repo, err := git2go.Clone(url, path, &git2go.CloneOptions{
|
||||||
FetchOptions: git2go.FetchOptions{
|
FetchOptions: git2go.FetchOptions{
|
||||||
DownloadTags: git2go.DownloadTagsAll,
|
DownloadTags: git2go.DownloadTagsAll,
|
||||||
|
@ -323,7 +332,6 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
|
||||||
defer cc.Free()
|
defer cc.Free()
|
||||||
return buildCommit(cc, "refs/tags/"+c.Tag), nil
|
return buildCommit(cc, "refs/tags/"+c.Tag), nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type CheckoutCommit struct {
|
type CheckoutCommit struct {
|
||||||
Commit string
|
Commit string
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckoutBranch_Checkout(t *testing.T) {
|
func TestCheckoutBranch_checkoutUnmanaged(t *testing.T) {
|
||||||
repo, err := initBareRepo(t)
|
repo, err := initBareRepo(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -126,7 +126,7 @@ func TestCheckoutBranch_Checkout(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckoutTag_Checkout(t *testing.T) {
|
func TestCheckoutTag_checkoutUnmanaged(t *testing.T) {
|
||||||
type testTag struct {
|
type testTag struct {
|
||||||
name string
|
name string
|
||||||
annotated bool
|
annotated bool
|
||||||
|
|
Loading…
Reference in New Issue