Title: Fix Git.execute shell use and reporting bugs by EliahKagan · Pull Request #1687 · gitpython-developers/GitPython · GitHub
Open Graph Title: Fix Git.execute shell use and reporting bugs by EliahKagan · Pull Request #1687 · gitpython-developers/GitPython
X Title: Fix Git.execute shell use and reporting bugs by EliahKagan · Pull Request #1687 · gitpython-developers/GitPython
Description: Fixes #1685 Fixes #1686 Changes to git module code This updates the shell variable itself, only when it is None, from self.USE_SHELL. (That attribute usually gets its value from Git.USE_SHELL rather than being separately an instance attribute. But self.USE_SHELL is an idiomatic way to access it. Furthermore, although people probably shouldn't set it on instances, people may expect that this is permitted.) Now: USE_SHELL is used as a fallback only. When shell=False is passed, USE_SHELL is no longer consulted. Thus shell=False always keeps a shell from being used, even in the non-default case where the USE_SHELL attribute has been set to True. The debug message printed to the log shows the actual value that is being passed to Popen, because the updated shell variable is used both to produce that message and in the Popen call. New tests This also (actually, first) adds tests, some to check that the correct value is always passed as shell= when Git.execute calls Popen, and others to check that whatever it passes is the same as it claims to be passing in the log. I've made them two separate test methods rather than a test method with multiple assertions, because I think the results of these particular tests are easier to understand that way (even compared to the option of using self.subTest). But the major shared logic is extracted to a helper function, where its important subtleties are commented. I have verified that the tests fail, in the expected way, before the bugs are fixed, and then pass, and that these are both the case even on native Windows where we don't (yet) have CI jobs. The tests cover the six combinations of valid values of the shell= argument to Git.execute (None, False, and True) and Git.USE_SHELL (False and True). I used ddt for this, so there are only two test methods, even though there are six test cases. The tests are simple in principle, with the main source of complexity being the question of how to deal with how the command argument to Popen typically differs, including by type, based on the shell argument, yet the tests must not misbehave, nor induce extraneous misbehavior, even when the code under test has a bug that would ordinarily prevent such agreement. On Python 3.7 only, this adds mock as a development dependency (in the test extra, not as a regular dependency). mock is a backport of unittest.mock, and a couple of my assertions use a handy feature that was introduced to the mock library in Python 3.8. Besides being harder to write without it, I believe it would be less clearly expressed. (Details are commented with the import logic.) While adding the new tests, I also renamed test_it_executes_git_to_shell_and_returns_result to test_it_executes_git_and_returns_result, because that test case does not test that a shell is used to run git (and a shell is not used in that test).
Open Graph Description: Fixes #1685 Fixes #1686 Changes to git module code This updates the shell variable itself, only when it is None, from self.USE_SHELL. (That attribute usually gets its value from Git.USE_SHELL rathe...
X Description: Fixes #1685 Fixes #1686 Changes to git module code This updates the shell variable itself, only when it is None, from self.USE_SHELL. (That attribute usually gets its value from Git.USE_SHELL rathe...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1687
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:c33e5784-fca6-108d-d48a-9aa66080c50e |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | A596:39D22:790254:A686E5:6968AFF4 |
| html-safe-nonce | ba1cbbb4fbb203949a7179dbfedee56dea2b443d76108d4c3b04105574906c03 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTk2OjM5RDIyOjc5MDI1NDpBNjg2RTU6Njk2OEFGRjQiLCJ2aXNpdG9yX2lkIjoiMzQyMjQzMjY1Mjc5MjczNzc4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1392858dd14514241a1b6502398c812d3828a07959f452a1ea4b1dcf82ad5c60 |
| hovercard-subject-tag | pull_request:1537693215 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/1687/checks |
| twitter:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| og:image:alt | Fixes #1685 Fixes #1686 Changes to git module code This updates the shell variable itself, only when it is None, from self.USE_SHELL. (That attribute usually gets its value from Git.USE_SHELL rathe... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3223a6503d318917691422cdadfbe16cd8fb21e5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width