Commit Graph

10 Commits

Author SHA1 Message Date
Julien P 6446d7b957
Protect access to transport.UnsupportedCapabilities inside repo.FetchContext ()
repo.FetchContext reads transport.UnsupportedCapabilities, which we
modify, leading to a potential data race in oncurrent calls to
setupGitRepo.
Wrap the call to repo.FetchContext with the global transportMutex.

Fixes https://github.com/pulumi/pulumi/issues/16516
2024-06-28 23:17:26 +00:00
Fraser Waters 13f3b6c32d
Fix datarace in setupGitRepo ()
<!--- 
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. -->

Fixes a datarace in setupGitRepo seen in CI:

```
=== FAIL: go/auto TestNewStackRemoteSource (44.69s)
==================
WARNING: DATA RACE
Read at 0x000002d35650 by goroutine 103:
  github.com/pulumi/pulumi/sdk/v3/go/auto.setupGitRepo()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/git.go:125 +0xf78
  github.com/pulumi/pulumi/sdk/v3/go/auto.NewLocalWorkspace()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace.go:778 +0x435
  github.com/pulumi/pulumi/sdk/v3/go/auto.NewStackRemoteSource()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace.go:1114 +0x2c4
  github.com/pulumi/pulumi/sdk/v3/go/auto.TestNewStackRemoteSource()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace_test.go:465 +0x326
  testing.tRunner()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1648 +0x44

Previous write at 0x000002d35650 by goroutine 104:
  github.com/pulumi/pulumi/sdk/v3/go/auto.setupGitRepo()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/git.go:139 +0x11d1
  github.com/pulumi/pulumi/sdk/v3/go/auto.NewLocalWorkspace()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace.go:778 +0x435
  github.com/pulumi/pulumi/sdk/v3/go/auto.UpsertStackRemoteSource()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace.go:1133 +0x2c4
  github.com/pulumi/pulumi/sdk/v3/go/auto.TestUpsertStackRemoteSource()
      /Users/runner/work/pulumi/pulumi/sdk/go/auto/local_workspace_test.go:559 +0x326
  testing.tRunner()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1595 +0x238
  testing.(*T).Run.func1()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1648 +0x44

Goroutine 103 (running) created at:
  testing.(*T).Run()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1648 +0x82a
  testing.runTests.func1()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:2054 +0x84
  testing.tRunner()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1595 +0x238
  testing.runTests()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:2052 +0x896
  testing.(*M).Run()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1925 +0xb57
  main.main()
      _testmain.go:159 +0x2e4

Goroutine 104 (running) created at:
  testing.(*T).Run()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1648 +0x82a
  testing.runTests.func1()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:2054 +0x84
  testing.tRunner()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1595 +0x238
  testing.runTests()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:2052 +0x896
  testing.(*M).Run()
      /Users/runner/hostedtoolcache/go/1.21.1/x64/src/testing/testing.go:1925 +0xb57
  main.main()
      _testmain.go:159 +0x2e4
==================
    testing.go:1465: race detected during execution of test
```

Pretty clear culprit of mutating a global variable in the go-git module.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- 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 - This was caught be existing tests
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] 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 Cloud,
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
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-24 14:34:43 +00:00
Bryce Lampe cbcad3277e
Allow shallow clones for local workspaces ()
<!--- 
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

This exposes a GitRepo option to enable shallow cloning repositories.
This is helpful in cases where the repo has a large history.


## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- 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 Cloud,
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
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-01 17:21:52 +00:00
Pat Gavlin 9306a4261b [go/auto/git] Fetch a commit if one is specified
If a commit hash is specified for a Git repo, explicitly fetch it before
attempting to check it out. This allows using commits that are not
fetched by default (e.g. GitHub test merge commits).
2023-03-06 09:27:51 -06:00
Michael Bridgen 3507b09a5d Support clones from Azure DevOps
In general, go-git can't clone from Azure DevOps, because the latter
requires the capabilities multi_ack and multi_ack_detailed, which aren't
implemented. However, there's now a workaround, which boils down to
this: pretend, for the initial clone, that those capabilities _are_
supported, and expect them not to be used.

(See https://github.com/go-git/go-git/pull/613 for more on this
workaround.)

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2023-02-02 16:56:51 +00:00
Fraser Waters 2ee0fb726a Clean up use of pkg/errors in sdk/go/auto 2023-01-06 22:50:45 +00:00
Michael Bridgen 4478bc0f69
Work with all kinds of branch names ()
* Generalise git branch test

In  the git checkout was adapted so it would work with simple
branch names (i.e., "main" rather than "refs/heads/main"). However, it
still won't work with a branch that's not the default branch -- this
test demonstrates so.

* Support all simple and full branch names

If you want to have a non-default branch checked out, you need to fetch
it _and_ make a local reference for it. If you don't giv e a specific
reference, *Repository.Clone(...) updates remote heads, but does not
create local refs.

So, to support the varieties of branch names that people might use, the
provided branch name needs to be interpreted, and used for the
*Repository.Clone(...).

* Support cloning at a tag

Although the field is .Branch, we might expect people to ask for a tag
too. It's probably possible, with some back and forth, to disambiguate
between a simple branch name and a simple tag name; but, for the sake of
simplicity, require people to give `refs/tags/tag`.

* Queue changelog entry

* Check more cases of supplied branch name

 - ... including things that should result in an error
 - verify that the remote named in a remote ref is "origin"; anything
   else is surely a mistake

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2022-08-22 13:41:17 +01:00
Fraser Waters c9094f2ceb
Update go-git to v5 ()
* Update go-git to v5

* Add to CHANGELOG
2022-08-09 12:46:28 +01:00
Michael Bridgen c48b9d9eaf
Accept short branch names in GitRepo.Branch ()
* Accept short branch names in GitRepo.Branch

Users often give short names for branches -- e.g., `dev`, rather than
`refs/heads/dev`. This commit makes that work rather than produce an
error, by adopting the heuristic that anything that doesn't look like a
full branch name (i.e., not starting with ref/heads/) must be a short
name.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2022-07-13 16:42:45 +01:00
Paul Stack 3fad2e5329 Removing x namespace from go/python/nodejs automation packages () 2021-04-14 19:32:18 +01:00