Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork938
Report actual attempted Git command when Git.refresh fails#1812
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
ba4cbae
Split test_refresh into two tests
EliahKaganf241808
Simplify test of refresh that should succeed
EliahKaganf98aadd
Have test of refresh that should fail assert command
EliahKagan24d6067
Fix wrong GitCommandNotFound command from refresh
EliahKagan3a34dee
Also test refresh with an already-absolute bad path
EliahKagan5ad7cb2
Start work on making refresh tests restore state
EliahKaganb3fc30e
Re-refresh to restore state after refresh tests
EliahKaganae28c98
Refactor _rollback_refresh slightly for clarity
EliahKagan3bb63f3
Condense FetchInfo.refresh using contextlib.suppress
EliahKagan9b7e15f
State what the refresh tests verify
EliahKaganFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletionsgit/cmd.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
33 changes: 11 additions & 22 deletionsgit/remote.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
53 changes: 45 additions & 8 deletionstest/test_git.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -44,6 +44,14 @@ def _patch_out_env(name): | ||
os.environ[name] = old_value | ||
@contextlib.contextmanager | ||
def _rollback_refresh(): | ||
try: | ||
yield Git.GIT_PYTHON_GIT_EXECUTABLE # Provide the old value for convenience. | ||
finally: | ||
refresh() | ||
@ddt.ddt | ||
class TestGit(TestBase): | ||
@classmethod | ||
@@ -306,14 +314,43 @@ def test_cmd_override(self): | ||
): | ||
self.assertRaises(GitCommandNotFound, self.git.version) | ||
def test_refresh_bad_absolute_git_path(self): | ||
"""Bad absolute path arg is reported and not set.""" | ||
EliahKagan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
absolute_path = str(Path("yada").absolute()) | ||
expected_pattern = rf"\n[ \t]*cmdline: {re.escape(absolute_path)}\Z" | ||
with _rollback_refresh() as old_git_executable: | ||
with self.assertRaisesRegex(GitCommandNotFound, expected_pattern): | ||
refresh(absolute_path) | ||
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, old_git_executable) | ||
def test_refresh_bad_relative_git_path(self): | ||
"""Bad relative path arg is resolved to absolute path and reported, not set.""" | ||
absolute_path = str(Path("yada").absolute()) | ||
expected_pattern = rf"\n[ \t]*cmdline: {re.escape(absolute_path)}\Z" | ||
with _rollback_refresh() as old_git_executable: | ||
with self.assertRaisesRegex(GitCommandNotFound, expected_pattern): | ||
refresh("yada") | ||
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, old_git_executable) | ||
def test_refresh_good_absolute_git_path(self): | ||
"""Good absolute path arg is set.""" | ||
absolute_path = shutil.which("git") | ||
with _rollback_refresh(): | ||
refresh(absolute_path) | ||
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path) | ||
def test_refresh_good_relative_git_path(self): | ||
"""Good relative path arg is resolved to absolute path and set.""" | ||
absolute_path = shutil.which("git") | ||
dirname, basename = osp.split(absolute_path) | ||
with cwd(dirname): | ||
with _rollback_refresh(): | ||
refresh(basename) | ||
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path) | ||
def test_options_are_passed_to_git(self): | ||
# This works because any command after git --version is ignored. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.