From 6e5b4c719b396e0affd4e9ca7f09700398c6b6be Mon Sep 17 00:00:00 2001 From: Jan Keromnes Date: Fri, 14 May 2021 17:03:34 +0000 Subject: [PATCH] [content-init] If re-applying stashed changes from an unclean prebuild after checkout fails, throw them away instead of leaving merge conflicts in the workspace --- components/content-service/pkg/initializer/prebuild.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/content-service/pkg/initializer/prebuild.go b/components/content-service/pkg/initializer/prebuild.go index 29af175e9581de..8178e9ab77b5c8 100644 --- a/components/content-service/pkg/initializer/prebuild.go +++ b/components/content-service/pkg/initializer/prebuild.go @@ -110,7 +110,12 @@ func (p *PrebuildInitializer) Run(ctx context.Context, mappings []archive.IDMapp // If any of these cleanup operations fail that's no reason to fail ws initialization. // It just results in a slightly degraded state. if didStash { - _ = p.Git.Git(ctx, "stash", "pop") + err = p.Git.Git(ctx, "stash", "pop") + if err != nil { + // If restoring the stashed changes produces merge conflicts on the new Git ref, simply + // throw them away (they'll remain in the stash, but are likely outdated anyway). + _ = p.Git.Git(ctx, "reset", "--hard") + } } log.Debug("prebuild initializer Git operations complete")