Skip to content

Commit

Permalink
Merge #11124
Browse files Browse the repository at this point in the history
11124: Report unstaged changes from GitCloneOrPull r=justinvp a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

To help with #11121

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
  • Loading branch information
bors[bot] and Frassle committed Oct 24, 2022
2 parents 1387156 + 55d66c8 commit 6944c30
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions sdk/go/common/util/gitutil/git.go
Expand Up @@ -324,19 +324,56 @@ func gitCloneOrPull(url string, referenceName plumbing.ReferenceName, path strin
return err
}

if err = w.Pull(&git.PullOptions{
if cloneErr = w.Pull(&git.PullOptions{
ReferenceName: referenceName,
SingleBranch: true,
Force: true,
}); err != nil && err != git.NoErrAlreadyUpToDate {
return err
}); cloneErr == git.NoErrAlreadyUpToDate {
return nil
}
} else {
return cloneErr
}
}

return nil
if cloneErr == git.ErrUnstagedChanges {
// See https://github.com/pulumi/pulumi/issues/11121. We seem to be getting intermittent unstaged
// changes errors, which is very hard to reproduce. This block of code catches this error and tries to
// do a diff to see what the unstaged change is and tells the user to report this error to the above
// ticket.

repo, err := git.PlainOpen(path)
if err != nil {
return fmt.Errorf(
"GitCloneOrPull reported unstaged changes, but the repo couldn't be opened to check: %w\n"+
"Please report this to https://github.com/pulumi/pulumi/issues/11121.", err)
}

worktree, err := repo.Worktree()
if err != nil {
return fmt.Errorf(
"GitCloneOrPull reported unstaged changes, but the worktree couldn't be opened to check: %w\n"+
"Please report this to https://github.com/pulumi/pulumi/issues/11121.", err)
}

status, err := worktree.Status()
if err != nil {
return fmt.Errorf(
"GitCloneOrPull reported unstaged changes, but the worktree status couldn't be fetched to check: %w\n"+
"Please report this to https://github.com/pulumi/pulumi/issues/11121.", err)
}

messages := make([]string, 0)
for path, stat := range status {
if stat.Worktree != git.Unmodified {
messages = append(messages, fmt.Sprintf("%s was %c", path, rune(stat.Worktree)))
}
}

return fmt.Errorf("GitCloneOrPull reported unstaged changes: %s\n"+
"Please report this to https://github.com/pulumi/pulumi/issues/11121.",
strings.Join(messages, "\n"))
}

return cloneErr
}

// gitCloneOrPullSystemGit uses the `git` command to pull or clone repositories.
Expand Down

0 comments on commit 6944c30

Please sign in to comment.