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

Fix exit on errexit when return code is used for checks #34

Merged
merged 1 commit into from
Nov 17, 2021

Conversation

flaix
Copy link
Contributor

@flaix flaix commented Nov 16, 2021

At the beginning of the script, the return code of git ls-remote
is used in a check while errexit is active. This does not work
because in case the git ls-remote returns a non-zero code, the
script will exit immediately and the line checking the return code
in an if clause is never reached.

For this to work, errexit needs to be temporarily disabled and
the return code stored in a variable for later use.

At the beginning of the script, the return code of `git ls-remote`
is used in a check while `errexit` is active. This does not work
because in case the `git ls-remote` returns a non-zero code, the
script will exit immediately and the line checking the return code
in an `if` clause is never reached.

For this to work, `errexit` needs to be temporarily disabled and
the return code stored in a variable for later use.
@jgehrcke
Copy link
Owner

errexit needs to be temporarily disabled

Right! It's a common trap which I've hit personally or seen hit many times in the past N years -- I so much miss (Pythonic) context managers for implementing behavior like this.

@jgehrcke
Copy link
Owner

(for the record, this adds to the patch #32)

@jgehrcke jgehrcke merged commit bf72b2f into jgehrcke:main Nov 17, 2021
@flaix flaix deleted the fix-branchcheck branch November 17, 2021 10:35
@gautamkrishnar
Copy link
Contributor

@flaix thanks for fixing this 👍🏻

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.

None yet

3 participants