Create a git commit for the checkpoint.
(reason: str)
| 131 | |
| 132 | |
| 133 | def _create_git_commit(reason: str) -> Optional[str]: |
| 134 | """Create a git commit for the checkpoint.""" |
| 135 | try: |
| 136 | # Check if we're in a git repo |
| 137 | result = subprocess.run( |
| 138 | ["git", "rev-parse", "--git-dir"], |
| 139 | cwd=CODE_DIR, |
| 140 | capture_output=True, |
| 141 | text=True |
| 142 | ) |
| 143 | if result.returncode != 0: |
| 144 | return None |
| 145 | |
| 146 | # Stage all changes |
| 147 | subprocess.run( |
| 148 | ["git", "add", "-A"], |
| 149 | cwd=CODE_DIR, |
| 150 | capture_output=True |
| 151 | ) |
| 152 | |
| 153 | # Check if there are changes to commit |
| 154 | result = subprocess.run( |
| 155 | ["git", "diff", "--cached", "--quiet"], |
| 156 | cwd=CODE_DIR, |
| 157 | capture_output=True |
| 158 | ) |
| 159 | if result.returncode == 0: |
| 160 | # No changes |
| 161 | result = subprocess.run( |
| 162 | ["git", "rev-parse", "HEAD"], |
| 163 | cwd=CODE_DIR, |
| 164 | capture_output=True, |
| 165 | text=True |
| 166 | ) |
| 167 | return result.stdout.strip() if result.returncode == 0 else None |
| 168 | |
| 169 | # Create commit |
| 170 | subprocess.run( |
| 171 | ["git", "commit", "-m", f"Codey checkpoint: {reason}"], |
| 172 | cwd=CODE_DIR, |
| 173 | capture_output=True |
| 174 | ) |
| 175 | |
| 176 | # Get commit hash |
| 177 | result = subprocess.run( |
| 178 | ["git", "rev-parse", "HEAD"], |
| 179 | cwd=CODE_DIR, |
| 180 | capture_output=True, |
| 181 | text=True |
| 182 | ) |
| 183 | return result.stdout.strip() if result.returncode == 0 else None |
| 184 | |
| 185 | except Exception as e: |
| 186 | warning(f"Checkpoint: git commit failed: {e}") |
| 187 | return None |
| 188 | |
| 189 | |
| 190 | def rollback(checkpoint_id: str) -> bool: |
no test coverage detected