-
-
Notifications
You must be signed in to change notification settings - Fork 52
Add Git-based configuration management #334
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
Changes from all commits
efcd115
e65d97d
a8b2291
2552203
6d3117e
360c1ee
5260339
8ec22ba
cd07900
4114ac4
034d699
8d066dd
6292713
48e3ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| class GitManager: | ||
| def __init__(self, config_path: str): | ||
| self.config_path = Path(config_path) | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def init_repo(self): | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (self.config_path / ".git").exists(): | ||
| return False | ||
|
|
||
| subprocess.run(["git", "init"], cwd=self.config_path, check=True) | ||
| return True | ||
|
|
||
| def commit_all(self, message: str) -> bool: | ||
|
||
| subprocess.run(["git", "add", "."], cwd=self.config_path, check=True) | ||
|
|
||
| result = subprocess.run( | ||
| ["git", "commit", "-m", message], | ||
|
||
| cwd=self.config_path, | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
|
|
||
| if "nothing to commit" in result.stdout.lower(): | ||
| return False | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if result.returncode != 0: | ||
| raise RuntimeError(result.stderr.strip()) | ||
|
|
||
| return True | ||
|
|
||
| def history(self) -> str: | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result = subprocess.run( | ||
| ["git", "log", "--oneline", "--relative-date"], | ||
| cwd=self.config_path, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| if result.returncode != 0: | ||
| # No commits yet | ||
| return "" | ||
|
|
||
| return result.stdout.strip() | ||
|
|
||
| def rollback(self, commit_hash: str) -> None: | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| subprocess.run( | ||
| ["git", "checkout", commit_hash, "--", "."], cwd=self.config_path, check=True | ||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||
| from pathlib import Path | ||||
|
||||
| from pathlib import Path |
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect mock patch location. The patch decorator should target "cortex.config.git_manager.subprocess.run" instead of just "subprocess.run" to properly mock the subprocess module as imported in the GitManager module. The current patch may not work correctly depending on how the module is imported.
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete test assertions. The test only verifies that subprocess.run was called, but doesn't verify that it was called with the correct arguments (git checkout command with the specific commit hash). This makes the test less effective at catching regressions in the rollback functionality.
Uh oh!
There was an error while loading. Please reload this page.