From 487d1a03b8997c588de8507c0322b8a7c02272ce Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Wed, 26 Oct 2022 17:19:55 -0700 Subject: [PATCH] cli: Fix issue with pulumi new and unstaged files --- ...-work-around-a-go-git-issue-with-ignored-files.yaml | 4 ++++ sdk/go/common/util/gitutil/git.go | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 changelog/pending/20221027--cli--hard-reset-the-templates-checkout-to-work-around-a-go-git-issue-with-ignored-files.yaml diff --git a/changelog/pending/20221027--cli--hard-reset-the-templates-checkout-to-work-around-a-go-git-issue-with-ignored-files.yaml b/changelog/pending/20221027--cli--hard-reset-the-templates-checkout-to-work-around-a-go-git-issue-with-ignored-files.yaml new file mode 100644 index 000000000000..5e4550e3d0e4 --- /dev/null +++ b/changelog/pending/20221027--cli--hard-reset-the-templates-checkout-to-work-around-a-go-git-issue-with-ignored-files.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: cli + description: Hard reset the templates checkout to work around a go-git issue with ignored files. diff --git a/sdk/go/common/util/gitutil/git.go b/sdk/go/common/util/gitutil/git.go index f5be48342559..0d34cff4a1ae 100644 --- a/sdk/go/common/util/gitutil/git.go +++ b/sdk/go/common/util/gitutil/git.go @@ -324,6 +324,16 @@ func gitCloneOrPull(url string, referenceName plumbing.ReferenceName, path strin return err } + // There are cases where go-git gets confused about files that were included in .gitignore + // and then later removed from .gitignore and added to the repository, leaving unstaged + // changes in the working directory after a pull. To address this, we'll first do a hard + // reset of the worktree before pulling to ensure it's in a good state. + if err := w.Reset(&git.ResetOptions{ + Mode: git.HardReset, + }); err != nil { + return err + } + if cloneErr = w.Pull(&git.PullOptions{ ReferenceName: referenceName, SingleBranch: true,