From 787ed7e0bfb3cf1da3025aff0c7770717a993667 Mon Sep 17 00:00:00 2001 From: Liz Prucka Date: Mon, 8 Aug 2022 17:52:00 +0000 Subject: pkg/vcs/git.go: fixed error in initializing submodules Adding a remote origin if one has not been initialized. --- pkg/vcs/git.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pkg/vcs/git.go') diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index 63901b850..f6f6ee276 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -103,7 +103,12 @@ func (git *git) CheckoutBranch(repo, branch string) (*Commit, error) { return nil, err } repoHash := hash.String([]byte(repo)) - // Ignore error as we can double add the same remote and that will fail. + // Because the HEAD is detached, submodules assumes "origin" to be the default + // remote when initializing. + // This sets "origin" to be the current remote. + // Ignore errors as we can double add or remove the same remote and that will fail. + git.git("remote", "rm", "origin") + git.git("remote", "add", "origin", repo) git.git("remote", "add", repoHash, repo) _, err := git.git("fetch", "--force", repoHash, branch) if err != nil { -- cgit mrf-deployment