PR: fix case where submodule cannot be initialized
Sometimes the commit is already cleaned up and Project Git cannot be initialized. This should not be an error. Only fatal error is if we can't update the PR to current state.
This commit is contained in:
@@ -33,7 +33,9 @@ func verifyRepositoryConfiguration(repo *models.Repository) error {
|
|||||||
|
|
||||||
func updateSubmoduleInPR(submodule, headSha string, git common.Git) {
|
func updateSubmoduleInPR(submodule, headSha string, git common.Git) {
|
||||||
common.LogDebug("updating submodule", submodule, "to HEAD", headSha)
|
common.LogDebug("updating submodule", submodule, "to HEAD", headSha)
|
||||||
common.PanicOnError(git.GitExec(common.DefaultGitPrj, "submodule", "update", "--init", "--checkout", "--depth", "1", submodule))
|
// NOTE: this can fail if current PrjGit is pointing to outdated, GC'ed commit
|
||||||
|
// as long as we can update to newer one later, we are still OK
|
||||||
|
git.GitExec(common.DefaultGitPrj, "submodule", "update", "--init", "--checkout", "--depth", "1", submodule)
|
||||||
common.PanicOnError(git.GitExec(path.Join(common.DefaultGitPrj, submodule), "fetch", "--depth", "1", "origin", headSha))
|
common.PanicOnError(git.GitExec(path.Join(common.DefaultGitPrj, submodule), "fetch", "--depth", "1", "origin", headSha))
|
||||||
common.PanicOnError(git.GitExec(path.Join(common.DefaultGitPrj, submodule), "checkout", headSha))
|
common.PanicOnError(git.GitExec(path.Join(common.DefaultGitPrj, submodule), "checkout", headSha))
|
||||||
}
|
}
|
||||||
@@ -325,10 +327,7 @@ func (pr *PRProcessor) Process(req *common.PullRequestWebhookEvent) error {
|
|||||||
common.LogDebug("Submodule parse done")
|
common.LogDebug("Submodule parse done")
|
||||||
|
|
||||||
reset_submodule := func(submodule, sha string) {
|
reset_submodule := func(submodule, sha string) {
|
||||||
spath := path.Join(common.DefaultGitPrj, submodule)
|
updateSubmoduleInPR(submodule, sha, git)
|
||||||
git.GitExecOrPanic(common.DefaultGitPrj, "submodule", "update", "--init", "--depth", "1", submodule)
|
|
||||||
git.GitExecOrPanic(spath, "fetch", "origin", sha)
|
|
||||||
git.GitExecOrPanic(spath, "checkout", sha)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for path, commit := range new_subs {
|
for path, commit := range new_subs {
|
||||||
|
|||||||
Reference in New Issue
Block a user