Create a new documentation branch with timestamp. Args: force: Force creation even if dirty working directory Returns: Branch name Raises: RepositoryError: If working directory is dirty (unless fo
(self, force: bool = False)
| 71 | |
| 72 | def create_documentation_branch(self, force: bool = False) -> str: |
| 73 | """ |
| 74 | Create a new documentation branch with timestamp. |
| 75 | |
| 76 | Args: |
| 77 | force: Force creation even if dirty working directory |
| 78 | |
| 79 | Returns: |
| 80 | Branch name |
| 81 | |
| 82 | Raises: |
| 83 | RepositoryError: If working directory is dirty (unless force=True) |
| 84 | """ |
| 85 | # Check working directory |
| 86 | if not force: |
| 87 | is_clean, status_msg = self.check_clean_working_directory() |
| 88 | if not is_clean: |
| 89 | raise RepositoryError( |
| 90 | "Working directory has uncommitted changes.\n\n" |
| 91 | f"{status_msg}\n\n" |
| 92 | "Cannot create documentation branch with uncommitted changes.\n" |
| 93 | "Please commit or stash your changes first:\n" |
| 94 | " git status\n" |
| 95 | ' git add -A && git commit -m "Your message"\n' |
| 96 | " # or\n" |
| 97 | " git stash\n\n" |
| 98 | "Then re-run: codewiki generate --create-branch" |
| 99 | ) |
| 100 | |
| 101 | # Generate branch name with timestamp |
| 102 | timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") |
| 103 | branch_name = f"docs/codewiki-{timestamp}" |
| 104 | |
| 105 | # Check if branch already exists (shouldn't happen with timestamp) |
| 106 | existing_branches = [b.name for b in self.repo.branches] |
| 107 | if branch_name in existing_branches: |
| 108 | # Append counter |
| 109 | counter = 1 |
| 110 | while f"{branch_name}-{counter}" in existing_branches: |
| 111 | counter += 1 |
| 112 | branch_name = f"{branch_name}-{counter}" |
| 113 | |
| 114 | try: |
| 115 | # Create and checkout new branch |
| 116 | new_branch = self.repo.create_head(branch_name) |
| 117 | new_branch.checkout() |
| 118 | return branch_name |
| 119 | except GitCommandError as e: |
| 120 | raise RepositoryError(f"Failed to create branch: {e}") |
| 121 | |
| 122 | def commit_documentation(self, docs_path: Path, message: Optional[str] = None) -> str: |
| 123 | """ |
| 124 | Commit generated documentation. |
no test coverage detected