Git Utils
Utilities for interacting with Git.
logger
module-attribute
logger = getLogger(__name__)
GitError
Bases: Exception
Custom exception for Git-related errors.
Source code in src/codemap/utils/git_utils.py
20 21 |
|
GitRepoContext
Context manager for efficient Git operations using pygit2.
Source code in src/codemap/utils/git_utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
logger
class-attribute
instance-attribute
logger = getLogger(__name__)
repo_root
class-attribute
instance-attribute
repo_root: Path | None = None
get_instance
classmethod
get_instance() -> GitRepoContext
Get a cached instance of GitRepoContext for a given repo_path.
Source code in src/codemap/utils/git_utils.py
32 33 34 35 36 37 |
|
get_repo_root
classmethod
get_repo_root(path: Path | None = None) -> Path
Get the root directory of the Git repository.
Source code in src/codemap/utils/git_utils.py
39 40 41 42 43 44 45 46 47 |
|
__init__
__init__() -> None
Initialize the GitRepoContext with the given repository path.
Source code in src/codemap/utils/git_utils.py
49 50 51 52 53 54 55 56 57 |
|
repo
instance-attribute
repo = Repository(str(repo_root))
branch
instance-attribute
branch = get_current_branch()
exclude_patterns
instance-attribute
exclude_patterns = _get_exclude_patterns()
tracked_files
instance-attribute
tracked_files = _get_tracked_files()
get_current_branch
get_current_branch() -> str
Get the current branch name of the Git repository.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The current branch name, or empty string if detached. |
Source code in src/codemap/utils/git_utils.py
130 131 132 133 134 135 136 137 138 139 |
|
get_file_git_hash
get_file_git_hash(file_path: str) -> str
Get the Git hash (blob ID) for a specific tracked file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the file relative to the repository root. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Git blob hash of the file, or empty string if not found. |
Source code in src/codemap/utils/git_utils.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
get_git_blame
get_git_blame(
file_path: str, start_line: int, end_line: int
) -> list[GitBlameSchema]
Get the Git blame for a specific range of lines in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the file relative to the repository root. |
required |
start_line
|
int
|
The starting line number of the range. |
required |
end_line
|
int
|
The ending line number of the range. |
required |
Returns:
Type | Description |
---|---|
list[GitBlameSchema]
|
list[GitBlameSchema]: A list of Git blame results. |
Source code in src/codemap/utils/git_utils.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
get_metadata_schema
get_metadata_schema(
file_path: str, start_line: int, end_line: int
) -> GitMetadataSchema
Derive the complete GitMetadataSchema for a given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the file relative to the repository root. |
required |
start_line
|
int
|
The starting line number of the range. |
required |
end_line
|
int
|
The ending line number of the range. |
required |
Returns:
Name | Type | Description |
---|---|---|
GitMetadataSchema |
GitMetadataSchema
|
The metadata for the file in the git repository. |
Source code in src/codemap/utils/git_utils.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
get_untracked_files
get_untracked_files() -> list[str]
Get a list of untracked files in the repository.
Source code in src/codemap/utils/git_utils.py
312 313 314 315 |
|
is_git_ignored
is_git_ignored(file_path: str) -> bool
Check if a file is ignored by Git.
Source code in src/codemap/utils/git_utils.py
317 318 319 |
|
is_file_tracked
is_file_tracked(file_path: str) -> bool
Check if a file is tracked in the Git repository.
Source code in src/codemap/utils/git_utils.py
321 322 323 |
|
unstage_files
unstage_files(files: list[str]) -> None
Unstage the specified files.
Source code in src/codemap/utils/git_utils.py
325 326 327 328 329 |
|
switch_branch
switch_branch(branch_name: str) -> None
Switch the current Git branch to the specified branch name.
Source code in src/codemap/utils/git_utils.py
331 332 333 334 |
|
stage_files
stage_files(files: list[str]) -> None
Stage the specified files.
Source code in src/codemap/utils/git_utils.py
336 337 338 339 340 |
|
commit
commit(message: str) -> None
Create a commit with the given message.
Source code in src/codemap/utils/git_utils.py
342 343 344 345 346 347 348 |
|