Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set upstream remote to track all branches after initial fetch #7542

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented Jun 7, 2023

After running repo clone set the upstream remote to track all branches instead of just the default branch.

This PR also adds a Copy() method to the git client as that pattern had been used a couple of times across the codebase.

Fixes #5385

@samcoe samcoe requested a review from a team as a code owner June 7, 2023 07:34
@samcoe samcoe requested review from vilmibm and removed request for a team June 7, 2023 07:34
@samcoe samcoe self-assigned this Jun 7, 2023
Comment on lines -516 to -539
func (c *Client) IsLocalGitRepo(ctx context.Context) (bool, error) {
_, err := c.GitDir(ctx)
if err != nil {
var execError errWithExitCode
if errors.As(err, &execError) && execError.ExitCode() == 128 {
return false, nil
}
return false, err
}
return true, nil
}

func (c *Client) UnsetRemoteResolution(ctx context.Context, name string) error {
args := []string{"config", "--unset", fmt.Sprintf("remote.%s.gh-resolved", name)}
cmd, err := c.Command(ctx, args...)
if err != nil {
return err
}
_, err = cmd.Output()
if err != nil {
return err
}
return nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These just got moved upwards in the file, no actual changes to the methods.

Copy link
Member

@williammartin williammartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! Thanks.

gc := gitClient.Copy()
gc.RepoDir = cloneDir

_, err = gc.AddRemote(ctx, upstreamName, upstreamURL, []string{canonicalRepo.Parent.DefaultBranchRef.Name})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about you but I kind of like the WithRepoDir modifier pattern, it's just a shame that it doesn't "put it back the way it was" so to speak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not exactly following. The WithRepoDir modifier does keep the git client directory unchanged and just modifies the single command, but in this case we were now up to 3 commands that needed to be modified so it seemed like an appropriate time to create a new git client specifically targeted at the cloneDir directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake! I thought it modified the RepoDir field on the git client rather than appending a -C just for this command.

I actually quite like that pattern even if used multiple times. Generally, I find copy semantics in languages with limited mutation control to be difficult to reason about and a regular source of "oops I modified this thing here and I didn't expect it to be modified there".

Not a worry for this though, I think it's a sensible pattern to explore. Thanks for the correction.

@samcoe samcoe merged commit fac4971 into trunk Jun 12, 2023
@samcoe samcoe deleted the fix-repo-clone-fetch branch June 12, 2023 00:23
renovate bot referenced this pull request in scottames/dots Jun 23, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [aquaproj/aqua-registry](https://github.com/aquaproj/aqua-registry)
| minor | `v4.20.0` -> `v4.21.1` |
| [cli/cli](https://github.com/cli/cli) | minor | `v2.30.0` ->
`v2.31.0` |
| [weaveworks/eksctl](https://github.com/weaveworks/eksctl) | minor |
`v0.145.0` -> `v0.146.0` |
| [zellij-org/zellij](https://github.com/zellij-org/zellij) | patch |
`v0.37.1` -> `v0.37.2` |

---

### Release Notes

<details>
<summary>aquaproj/aqua-registry</summary>

###
[`v4.21.1`](https://github.com/aquaproj/aqua-registry/releases/tag/v4.21.1)

[Compare
Source](https://github.com/aquaproj/aqua-registry/compare/v4.21.0...v4.21.1)


[Issues](https://github.com/aquaproj/aqua-registry/issues?q=is%3Aissue+milestone%3Av4.21.1)
| [Pull
Requests](https://github.com/aquaproj/aqua-registry/pulls?q=is%3Apr+milestone%3Av4.21.1)
| aquaproj/aqua-registry@v4.21.0...v4.21.1

#### Fixes


[#&#8203;13199](https://github.com/aquaproj/aqua-registry/issues/13199)
kubernetes-sigs/kustomize: Follow up changes of kustomize v5.1.0

-
[https://github.com/kubernetes-sigs/kustomize/issues/5220](https://github.com/kubernetes-sigs/kustomize/issues/5220)

###
[`v4.21.0`](https://github.com/aquaproj/aqua-registry/releases/tag/v4.21.0)

[Compare
Source](https://github.com/aquaproj/aqua-registry/compare/v4.20.0...v4.21.0)


[Issues](https://github.com/aquaproj/aqua-registry/issues?q=is%3Aissue+milestone%3Av4.21.0)
| [Pull
Requests](https://github.com/aquaproj/aqua-registry/pulls?q=is%3Apr+milestone%3Av4.21.0)
| aquaproj/aqua-registry@v4.20.0...v4.21.0

#### 🎉 New Packages


[#&#8203;13173](https://github.com/aquaproj/aqua-registry/issues/13173)
[assetnote/surf](https://github.com/assetnote/surf): Escalate your
SSRF vulnerabilities on Modern Cloud Environments. `surf` allows you to
filter a list of hosts, returning a list of viable SSRF candidates

[#&#8203;13174](https://github.com/aquaproj/aqua-registry/issues/13174)
[iyear/tdl](https://github.com/iyear/tdl): A Telegram downloader
written in Golang

[#&#8203;13172](https://github.com/aquaproj/aqua-registry/issues/13172)
[nikolaydubina/go-cover-treemap](https://github.com/nikolaydubina/go-cover-treemap):
Go code coverage to SVG treemap
[@&#8203;iwata](https://github.com/iwata)

</details>

<details>
<summary>cli/cli</summary>

### [`v2.31.0`](https://github.com/cli/cli/releases/tag/v2.31.0):
GitHub CLI 2.31.0

[Compare Source](https://github.com/cli/cli/compare/v2.30.0...v2.31.0)

#### What's New

- New suite of `project` commands for interacting with and manipulating
projects. Huge shoutout 🥳 for the time and effort put into this work by
[@&#8203;mntlty](https://github.com/mntlty) in
[https://github.com/cli/cli/pull/7375](https://github.com/cli/cli/pull/7375)
[https://github.com/cli/cli/pull/7578](https://github.com/cli/cli/pull/7578)
- New `search code` command by
[@&#8203;joshkraft](https://github.com/joshkraft) in
[https://github.com/cli/cli/pull/7376](https://github.com/cli/cli/pull/7376)
- New `cs view` command by
[@&#8203;dmgardiner25](https://github.com/dmgardiner25) in
[https://github.com/cli/cli/pull/7496](https://github.com/cli/cli/pull/7496)
[https://github.com/cli/cli/pull/7539](https://github.com/cli/cli/pull/7539)

#### What's Changed

- `api`: output a single JSON array in REST pagination mode by
[@&#8203;mislav](https://github.com/mislav) in
[https://github.com/cli/cli/pull/7190](https://github.com/cli/cli/pull/7190)
- `api`: support array params in GET queries by
[@&#8203;mislav](https://github.com/mislav) in
[https://github.com/cli/cli/pull/7513](https://github.com/cli/cli/pull/7513)
- `api`: force method to uppercase by
[@&#8203;ffalor](https://github.com/ffalor) in
[https://github.com/cli/cli/pull/7514](https://github.com/cli/cli/pull/7514)
- `alias`: Allow aliases to recognize extended commands by
[@&#8203;srz-zumix](https://github.com/srz-zumix) in
[https://github.com/cli/cli/pull/7523](https://github.com/cli/cli/pull/7523)
- `alias import`: Fix `--clobber` flag by
[@&#8203;samcoe](https://github.com/samcoe) in
[https://github.com/cli/cli/pull/7569](https://github.com/cli/cli/pull/7569)
- `run rerun`: Improve docs around `--job` flag by
[@&#8203;williammartin](https://github.com/williammartin) in
[https://github.com/cli/cli/pull/7527](https://github.com/cli/cli/pull/7527)
- `run view`: Support viewing logs for jobs with composite actions by
[@&#8203;williammartin](https://github.com/williammartin) in
[https://github.com/cli/cli/pull/7526](https://github.com/cli/cli/pull/7526)
- `gist edit`: Add selector option to `gist edit` command by
[@&#8203;kousikmitra](https://github.com/kousikmitra) in
[https://github.com/cli/cli/pull/7537](https://github.com/cli/cli/pull/7537)
- `repo clone`: Set upstream remote to track all branches after initial
fetch by [@&#8203;samcoe](https://github.com/samcoe) in
[https://github.com/cli/cli/pull/7542](https://github.com/cli/cli/pull/7542)
- `extension`: Speed up listing extensions by lazy-loading extension
information when needed by [@&#8203;mislav](https://github.com/mislav)
in
[https://github.com/cli/cli/pull/7493](https://github.com/cli/cli/pull/7493)
- `auth`: Add timeouts to keyring operations by
[@&#8203;samcoe](https://github.com/samcoe) in
[https://github.com/cli/cli/pull/7580](https://github.com/cli/cli/pull/7580)
- `auth status`: write to stdout on success by
[@&#8203;rajhawaldar](https://github.com/rajhawaldar) in
[https://github.com/cli/cli/pull/7540](https://github.com/cli/cli/pull/7540)
- `completion`: Fix bash completions for extensions and aliases by
[@&#8203;mislav](https://github.com/mislav) in
[https://github.com/cli/cli/pull/7525](https://github.com/cli/cli/pull/7525)
- `issue/pr view`: alphabetically sort labels for `gh pr/issue view` by
[@&#8203;ffalor](https://github.com/ffalor) in
[https://github.com/cli/cli/pull/7587](https://github.com/cli/cli/pull/7587)
- Fix error handling for extension and shell alias commands by
[@&#8203;samcoe](https://github.com/samcoe) in
[https://github.com/cli/cli/pull/7567](https://github.com/cli/cli/pull/7567)
- Fix pkg imported more than once by
[@&#8203;testwill](https://github.com/testwill) in
[https://github.com/cli/cli/pull/7591](https://github.com/cli/cli/pull/7591)
- Refactor a nested if statement by
[@&#8203;yanskun](https://github.com/yanskun) in
[https://github.com/cli/cli/pull/7596](https://github.com/cli/cli/pull/7596)
- Fix a typo by
[@&#8203;lerocknrolla](https://github.com/lerocknrolla) in
[https://github.com/cli/cli/pull/7557](https://github.com/cli/cli/pull/7557)
- Fix flaky test by [@&#8203;samcoe](https://github.com/samcoe) in
[https://github.com/cli/cli/pull/7515](https://github.com/cli/cli/pull/7515)
- Credential rotations, renames and decouplings from Mislav by
[@&#8203;williammartin](https://github.com/williammartin) in
[https://github.com/cli/cli/pull/7544](https://github.com/cli/cli/pull/7544)
- build(deps): bump github.com/cli/go-gh/v2 from 2.0.0 to 2.0.1 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/cli/cli/pull/7546](https://github.com/cli/cli/pull/7546)
- build(deps): bump github.com/AlecAivazis/survey/v2 from 2.3.6 to 2.3.7
by [@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/cli/cli/pull/7576](https://github.com/cli/cli/pull/7576)

#### New Contributors

- [@&#8203;srz-zumix](https://github.com/srz-zumix) made their first
contribution in
[https://github.com/cli/cli/pull/7523](https://github.com/cli/cli/pull/7523)
- [@&#8203;lerocknrolla](https://github.com/lerocknrolla) made their
first contribution in
[https://github.com/cli/cli/pull/7557](https://github.com/cli/cli/pull/7557)
- [@&#8203;testwill](https://github.com/testwill) made their first
contribution in
[https://github.com/cli/cli/pull/7591](https://github.com/cli/cli/pull/7591)
- [@&#8203;rajhawaldar](https://github.com/rajhawaldar) made their
first contribution in
[https://github.com/cli/cli/pull/7540](https://github.com/cli/cli/pull/7540)

**Full Changelog**: cli/cli@v2.30.0...v2.31.0

</details>

<details>
<summary>weaveworks/eksctl</summary>

###
[`v0.146.0`](https://github.com/weaveworks/eksctl/releases/tag/v0.146.0):
eksctl 0.146.0 (permalink)

[Compare
Source](https://github.com/weaveworks/eksctl/compare/0.145.0...0.146.0)

### Release v0.146.0

#### 🎯 Improvements

- Update vpc-cni to 1.12.6
([#&#8203;6692](https://github.com/weaveworks/eksctl/issues/6692))

#### 🧰 Maintenance

- Bump dependencies
([#&#8203;6690](https://github.com/weaveworks/eksctl/issues/6690))

#### 📝 Documentation

- New eksctl channel
([#&#8203;6697](https://github.com/weaveworks/eksctl/issues/6697))

#### Acknowledgments

Weaveworks would like to sincerely thank:
[@&#8203;wind0r](https://github.com/wind0r)

</details>

<details>
<summary>zellij-org/zellij</summary>

###
[`v0.37.2`](https://github.com/zellij-org/zellij/releases/tag/v0.37.2)

[Compare
Source](https://github.com/zellij-org/zellij/compare/v0.37.1...v0.37.2)

This is a patch release to fix some minor issues in the previous
release.

#### What's Changed

- hotfix: include theme files into binary by
[@&#8203;jaeheonji](https://github.com/jaeheonji) in
[https://github.com/zellij-org/zellij/pull/2566](https://github.com/zellij-org/zellij/pull/2566)
- fix(plugins): make hide_self api idempotent by
[@&#8203;imsnif](https://github.com/imsnif) in
[https://github.com/zellij-org/zellij/pull/2568](https://github.com/zellij-org/zellij/pull/2568)

**Full Changelog**:
zellij-org/zellij@v0.37.1...v0.37.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/scottames/dots).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMzEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants