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

Properly swallow errors if deleting a remote fails #505

Merged
merged 2 commits into from
Sep 8, 2024

Conversation

imphil
Copy link
Contributor

@imphil imphil commented Aug 19, 2024

deleteRemote() intends to return successfully if
the to-be-deleted remote does not exist. In this case, git returns an
exit code of 2, and outputs a message to stderr. Depending on the locale
of the user's system, this error message might be localized.
spawnPromise() and spawnStream() try to set the locale to en_US,
but there are no guarantees that this locale is actually available on
the user's system.

Instead of doing fragile locale-dependent string parsing, simply use the
exit code we get from git in this case and act on that.

Fix the mocks in the tests to behave like the real-world git, and add a
test for the non-English case as well.

Fixes #507

`deleteRemote()` intends to return successfully if
the to-be-deleted remote does not exist. In this case, git returns an
exit code of 2, and outputs a message to stderr. Depending on the locale
of the user's system, this error message might be localized.
`spawnPromise()` and `spawnStream()` try to set the locale to `en_US`,
but there are no guarantees that this locale is actually available on
the user's system.

Instead of doing fragile locale-dependent string parsing, simply use the
exit code we get from git in this case and act on that.

Fix the mocks in the tests to behave like the real-world git, and add a
test for the non-English case as well.
imphil added a commit to imphil/backport that referenced this pull request Aug 19, 2024
`LANG=en_US` is not guaranteed to exist on any system (it does not, for
strange reasons, exist on mine). Choose `LANG=C`, which is guaranteed to
exist. It has the side-effect of typically using an encoding other than
UTF-8 for the tool output (e.g., ISO 8859-1). Apart from messages
printed into the log in this encoding that should hopefully have no
negative side-effects.

See sorenlouv#505 for a case where
code was assuming that output would always be English, and failed if it
wasn't.
sorenlouv added a commit that referenced this pull request Sep 6, 2024
`LANG=en_US` is not guaranteed to exist on any system (it does not, for
strange reasons, exist on mine). Choose `LANG=C`, which is guaranteed to
exist. It has the side-effect of typically using an encoding other than
UTF-8 for the tool output (e.g., ISO 8859-1). Apart from messages
printed into the log in this encoding that should hopefully have no
negative side-effects.

See #505 for a case where
code was assuming that output would always be English, and failed if it
wasn't.

Co-authored-by: Søren Louv-Jansen <[email protected]>
@sorenlouv sorenlouv merged commit 0bc0a61 into sorenlouv:main Sep 8, 2024
2 of 3 checks passed
@sorenlouv
Copy link
Owner

Released in 9.6.0

imphil added a commit to imphil/backport that referenced this pull request Sep 23, 2024
Git 2.30.0 introduced a dedicated exit code (2) for when `git remote rm`
failed because the remote does not exist. Earlier versions of git
always returned code 128, and only parsing stderr could tell the error
conditions apart.

Support all versions of git by checking for both exit code 2, and exit
code 128 with the specific error message. The exit code 2 check remains
more robust against localized output, hence it's kept in addition to the
output parsing path that was removed in sorenlouv#505.

Fixes sorenlouv#509
sorenlouv pushed a commit to imphil/backport that referenced this pull request Sep 26, 2024
Git 2.30.0 introduced a dedicated exit code (2) for when `git remote rm`
failed because the remote does not exist. Earlier versions of git
always returned code 128, and only parsing stderr could tell the error
conditions apart.

Support all versions of git by checking for both exit code 2, and exit
code 128 with the specific error message. The exit code 2 check remains
more robust against localized output, hence it's kept in addition to the
output parsing path that was removed in sorenlouv#505.

Fixes sorenlouv#509
sorenlouv pushed a commit that referenced this pull request Sep 26, 2024
Git 2.30.0 introduced a dedicated exit code (2) for when `git remote rm`
failed because the remote does not exist. Earlier versions of git
always returned code 128, and only parsing stderr could tell the error
conditions apart.

Support all versions of git by checking for both exit code 2, and exit
code 128 with the specific error message. The exit code 2 check remains
more robust against localized output, hence it's kept in addition to the
output parsing path that was removed in #505.

Fixes #509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to delete remotes when setting up repo
2 participants