diff --git a/pkg/config/repo.go b/pkg/config/repo.go index 632301831..6cd0e9658 100644 --- a/pkg/config/repo.go +++ b/pkg/config/repo.go @@ -35,6 +35,10 @@ const ( HTTPBasic = "http-basic" ) +// remoteName is a remote name that airshipctl work with during document pull +// TODO (raliev) consider make this variable configurable via repoCheckout options +var remoteName = git.DefaultRemoteName + // Repository struct holds the information for the remote sources of manifest yaml documents. // Information such as location, authentication info, // as well as details of what to get such as branch, tag, commit it, etc. @@ -80,6 +84,8 @@ type RepoCheckout struct { RemoteRef string `json:"remoteRef,omitempty"` // ForceCheckout is a boolean to indicate whether to use the `--force` option when checking out ForceCheckout bool `json:"force"` + // LocalBranch is a boolean to indicate whether the Branch is local one. False by default + LocalBranch bool `json:"localBranch"` } // RepoCheckout methods @@ -223,7 +229,11 @@ func (repo *Repository) ToCheckoutOptions() *git.CheckoutOptions { co.Force = repo.CheckoutOptions.ForceCheckout switch { case repo.CheckoutOptions.Branch != "": - co.Branch = plumbing.NewBranchReferenceName(repo.CheckoutOptions.Branch) + if repo.CheckoutOptions.LocalBranch { + co.Branch = plumbing.NewBranchReferenceName(repo.CheckoutOptions.Branch) + } else { + co.Branch = plumbing.NewRemoteReferenceName(remoteName, repo.CheckoutOptions.Branch) + } case repo.CheckoutOptions.Tag != "": co.Branch = plumbing.NewTagReferenceName(repo.CheckoutOptions.Tag) case repo.CheckoutOptions.CommitHash != "": @@ -238,8 +248,9 @@ func (repo *Repository) ToCheckoutOptions() *git.CheckoutOptions { // CloneOptions describes how a clone should be performed func (repo *Repository) ToCloneOptions(auth transport.AuthMethod) *git.CloneOptions { return &git.CloneOptions{ - Auth: auth, - URL: repo.URLString, + Auth: auth, + URL: repo.URLString, + RemoteName: remoteName, } } diff --git a/pkg/config/testdata/config-string.yaml b/pkg/config/testdata/config-string.yaml index c8eebdf41..70891e9f3 100644 --- a/pkg/config/testdata/config-string.yaml +++ b/pkg/config/testdata/config-string.yaml @@ -28,6 +28,7 @@ manifests: branch: "" commitHash: "" force: false + localBranch: false tag: v1.0.1 url: http://dummy.url.com/manifests.git targetPath: /var/tmp/ diff --git a/pkg/config/testdata/manifest-string.yaml b/pkg/config/testdata/manifest-string.yaml index cb67f9432..e13a4c670 100644 --- a/pkg/config/testdata/manifest-string.yaml +++ b/pkg/config/testdata/manifest-string.yaml @@ -9,6 +9,7 @@ repositories: branch: "" commitHash: "" force: false + localBranch: false tag: v1.0.1 url: http://dummy.url.com/manifests.git targetPath: /var/tmp/ diff --git a/pkg/config/testdata/repo-checkout-string.yaml b/pkg/config/testdata/repo-checkout-string.yaml index 221fd041d..15f5d639e 100644 --- a/pkg/config/testdata/repo-checkout-string.yaml +++ b/pkg/config/testdata/repo-checkout-string.yaml @@ -1,4 +1,5 @@ branch: "" commitHash: "" force: false +localBranch: false tag: v1.0.1 diff --git a/pkg/config/testdata/repository-string.yaml b/pkg/config/testdata/repository-string.yaml index eebb784ef..ed2a85dd8 100644 --- a/pkg/config/testdata/repository-string.yaml +++ b/pkg/config/testdata/repository-string.yaml @@ -5,5 +5,6 @@ checkout: branch: "" commitHash: "" force: false + localBranch: false tag: v1.0.1 url: http://dummy.url.com/manifests.git diff --git a/pkg/document/pull/pull_test.go b/pkg/document/pull/pull_test.go index aeb5fbf4b..a8660e609 100644 --- a/pkg/document/pull/pull_test.go +++ b/pkg/document/pull/pull_test.go @@ -73,6 +73,7 @@ func TestPull(t *testing.T) { name: "TestCloneRepositoriesValidOpts", checkoutOpts: &config.RepoCheckout{ Branch: "master", + LocalBranch: true, ForceCheckout: false, }, error: nil,