API Reference¶
This section provides detailed API documentation for git-autosquash's core components. The documentation is auto-generated from docstrings to ensure accuracy.
Core Components¶
GitOps¶
The central interface for all Git operations with proper error handling.
git_autosquash.git_ops
¶
Git operations module for repository analysis and commands.
Classes¶
GitOps
¶
Handles git operations for repository analysis and validation.
Source code in src/git_autosquash/git_ops.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
|
__init__(repo_path: Optional[Path] = None) -> None
¶Initialize GitOps with optional repository path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_path
|
Optional[Path]
|
Path to git repository. Defaults to current directory. |
None
|
Source code in src/git_autosquash/git_ops.py
is_git_repo() -> bool
¶Check if current directory is inside a git repository.
Returns:
Type | Description |
---|---|
bool
|
True if in a git repository, False otherwise |
get_current_branch() -> Optional[str]
¶Get the current branch name.
Returns:
Type | Description |
---|---|
Optional[str]
|
Branch name if on a branch, None if detached HEAD |
Source code in src/git_autosquash/git_ops.py
get_merge_base_with_main(current_branch: str) -> Optional[str]
¶Find merge base with main/master branch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_branch
|
str
|
Current branch name |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Commit hash of merge base, or None if not found |
Source code in src/git_autosquash/git_ops.py
get_working_tree_status() -> dict[str, bool]
¶Get working tree status information.
Returns:
Type | Description |
---|---|
dict[str, bool]
|
Dictionary with status flags: has_staged, has_unstaged, is_clean |
Source code in src/git_autosquash/git_ops.py
has_commits_since_merge_base(merge_base: str) -> bool
¶Check if there are commits on current branch since merge base.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
merge_base
|
str
|
Merge base commit hash |
required |
Returns:
Type | Description |
---|---|
bool
|
True if there are commits to work with |
Source code in src/git_autosquash/git_ops.py
run_git_command(args: list[str], env: dict[str, str] | None = None) -> subprocess.CompletedProcess[str]
¶Run a git command and return the complete result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
list[str]
|
Git command arguments (without 'git') |
required |
env
|
dict[str, str] | None
|
Optional environment variables |
None
|
Returns:
Type | Description |
---|---|
CompletedProcess[str]
|
CompletedProcess with stdout, stderr, and return code |
Source code in src/git_autosquash/git_ops.py
Functions¶
HunkParser¶
Parses Git diff output into structured hunk objects.
git_autosquash.hunk_parser
¶
Diff parsing and hunk splitting module.
Classes¶
DiffHunk
dataclass
¶
Represents a single diff hunk with metadata.
Source code in src/git_autosquash/hunk_parser.py
HunkParser
¶
Parses git diff output into structured hunks.
Source code in src/git_autosquash/hunk_parser.py
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 |
|
__init__(git_ops: GitOps) -> None
¶Initialize HunkParser with GitOps instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
git_ops
|
GitOps
|
GitOps instance for running git commands |
required |
get_diff_hunks(line_by_line: bool = False) -> List[DiffHunk]
¶Extract hunks from current working tree or staged changes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line_by_line
|
bool
|
If True, split hunks line-by-line for finer granularity |
False
|
Returns:
Type | Description |
---|---|
List[DiffHunk]
|
List of DiffHunk objects representing changes |
Source code in src/git_autosquash/hunk_parser.py
get_file_content_at_lines(file_path: str, start_line: int, end_line: int) -> List[str]
¶Get file content at specific line range for context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the file |
required |
start_line
|
int
|
Starting line number (1-based) |
required |
end_line
|
int
|
Ending line number (1-based, inclusive) |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List of lines from the file, empty list on error |
Source code in src/git_autosquash/hunk_parser.py
BlameAnalyzer¶
Analyzes Git blame information to determine target commits for hunks.
git_autosquash.blame_analyzer
¶
Git blame analysis and target commit resolution.
Classes¶
TargetingMethod
¶
Bases: Enum
Enum for different targeting methods used to resolve a hunk.
Source code in src/git_autosquash/blame_analyzer.py
HunkTargetMapping
dataclass
¶
Maps a hunk to its target commit for squashing.
Source code in src/git_autosquash/blame_analyzer.py
BlameAnalyzer
¶
Analyzes git blame to determine target commits for hunks.
Source code in src/git_autosquash/blame_analyzer.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
|
__init__(git_ops: GitOps, merge_base: str) -> None
¶Initialize BlameAnalyzer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
git_ops
|
GitOps
|
GitOps instance for running git commands |
required |
merge_base
|
str
|
Merge base commit hash to limit scope |
required |
Source code in src/git_autosquash/blame_analyzer.py
analyze_hunks(hunks: List[DiffHunk]) -> List[HunkTargetMapping]
¶Analyze hunks and determine target commits for each.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hunks
|
List[DiffHunk]
|
List of DiffHunk objects to analyze |
required |
Returns:
Type | Description |
---|---|
List[HunkTargetMapping]
|
List of HunkTargetMapping objects with target commit information |
Source code in src/git_autosquash/blame_analyzer.py
get_commit_summary(commit_hash: str) -> str
¶Get a short summary of a commit for display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commit_hash
|
str
|
Commit hash to summarize |
required |
Returns:
Type | Description |
---|---|
str
|
Short commit summary (hash + subject) |
Source code in src/git_autosquash/blame_analyzer.py
set_target_for_file(file_path: str, target_commit: str) -> None
¶Set target commit for a file to ensure consistency.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
File path |
required |
target_commit
|
str
|
Commit hash to use as target |
required |
Source code in src/git_autosquash/blame_analyzer.py
clear_file_cache() -> None
¶Clear the file target cache for a fresh analysis.
Source code in src/git_autosquash/blame_analyzer.py
RebaseManager¶
Orchestrates interactive rebase operations to apply approved hunks.
git_autosquash.rebase_manager
¶
Interactive rebase manager for applying hunk mappings to historical commits.
Classes¶
RebaseConflictError
¶
Bases: Exception
Raised when rebase encounters conflicts that need user resolution.
Source code in src/git_autosquash/rebase_manager.py
RebaseManager
¶
Manages interactive rebase operations for squashing hunks to commits.
Source code in src/git_autosquash/rebase_manager.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
|
__init__(git_ops: GitOps, merge_base: str) -> None
¶Initialize rebase manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
git_ops
|
GitOps
|
Git operations handler |
required |
merge_base
|
str
|
Merge base commit hash |
required |
Source code in src/git_autosquash/rebase_manager.py
execute_squash(mappings: List[HunkTargetMapping]) -> bool
¶Execute the squash operation for approved mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mappings
|
List[HunkTargetMapping]
|
List of approved hunk to commit mappings |
required |
Returns:
Type | Description |
---|---|
bool
|
True if successful, False if user aborted |
Raises:
Type | Description |
---|---|
RebaseConflictError
|
If conflicts occur during rebase |
SubprocessError
|
If git operations fail |
Source code in src/git_autosquash/rebase_manager.py
abort_operation() -> None
¶is_rebase_in_progress() -> bool
¶Check if a rebase is currently in progress.
Returns:
Type | Description |
---|---|
bool
|
True if rebase is active |
Source code in src/git_autosquash/rebase_manager.py
get_rebase_status() -> Dict[str, Any]
¶Get current rebase status information.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary with rebase status details |
Source code in src/git_autosquash/rebase_manager.py
CLI Entry Point¶
Main¶
Command-line interface and entry point for git-autosquash.
git_autosquash.main
¶
CLI entry point for git-autosquash.
Classes¶
Functions¶
main() -> None
¶
Main entry point for git-autosquash command.
Source code in src/git_autosquash/main.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
|
TUI Components¶
AutoSquashApp¶
Main Textual application for the interactive approval workflow.
git_autosquash.tui.app
¶
Main Textual application for hunk approval workflow.
Classes¶
AutoSquashApp
¶
Bases: App[bool]
Main application for git-autosquash TUI.
Source code in src/git_autosquash/tui/app.py
__init__(mappings: List[HunkTargetMapping]) -> None
¶Initialize the application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mappings
|
List[HunkTargetMapping]
|
List of hunk to target commit mappings to review |
required |
Source code in src/git_autosquash/tui/app.py
compose() -> ComposeResult
¶on_mount() -> None
¶Handle application startup.
Source code in src/git_autosquash/tui/app.py
WelcomeScreen
¶
Bases: Screen[None]
Welcome screen showing project information.
Source code in src/git_autosquash/tui/app.py
compose() -> ComposeResult
¶Compose the welcome screen.
Source code in src/git_autosquash/tui/app.py
on_button_pressed(event: Button.Pressed) -> None
¶ApprovalScreen¶
Interactive screen for reviewing and approving hunk to commit mappings.
git_autosquash.tui.screens
¶
Screen implementations for git-autosquash TUI.
Classes¶
ApprovalScreen
¶
Bases: Screen[Union[bool, List[HunkTargetMapping]]]
Screen for approving hunk to commit mappings.
Source code in src/git_autosquash/tui/screens.py
17 18 19 20 21 22 23 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 |
|
__init__(mappings: List[HunkTargetMapping], **kwargs) -> None
¶Initialize approval screen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mappings
|
List[HunkTargetMapping]
|
List of hunk to commit mappings to review |
required |
Source code in src/git_autosquash/tui/screens.py
compose() -> ComposeResult
¶Compose the screen layout.
Source code in src/git_autosquash/tui/screens.py
on_mount() -> None
¶Handle screen mounting.
Source code in src/git_autosquash/tui/screens.py
on_hunk_selected(message: HunkMappingWidget.Selected) -> None
¶Handle hunk selection using O(1) lookup.
Source code in src/git_autosquash/tui/screens.py
on_approval_changed(message: HunkMappingWidget.ApprovalChanged) -> None
¶Handle approval status changes.
Source code in src/git_autosquash/tui/screens.py
on_ignore_changed(message: HunkMappingWidget.IgnoreChanged) -> None
¶Handle ignore status changes.
Source code in src/git_autosquash/tui/screens.py
on_button_pressed(event: Button.Pressed) -> None
¶Handle button presses.
Source code in src/git_autosquash/tui/screens.py
action_approve_all() -> None
¶Approve all hunks and continue.
Source code in src/git_autosquash/tui/screens.py
action_approve_all_toggle() -> None
¶action_continue() -> None
¶Continue with currently selected hunks.
Source code in src/git_autosquash/tui/screens.py
action_cancel() -> None
¶action_next_hunk() -> None
¶action_prev_hunk() -> None
¶action_ignore_all_toggle() -> None
¶action_toggle_current() -> None
¶Toggle the approval state of the currently selected hunk (with checkbox model, just toggle approve).
Source code in src/git_autosquash/tui/screens.py
Widgets¶
Custom widgets for the TUI interface.
git_autosquash.tui.widgets
¶
Custom widgets for git-autosquash TUI.
Classes¶
HunkMappingWidget
¶
Bases: Widget
Widget displaying a single hunk to commit mapping.
Source code in src/git_autosquash/tui/widgets.py
19 20 21 22 23 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 |
|
Selected
¶ApprovalChanged
¶
Bases: Message
Message sent when approval status changes.
Source code in src/git_autosquash/tui/widgets.py
IgnoreChanged
¶
Bases: Message
Message sent when ignore status changes.
Source code in src/git_autosquash/tui/widgets.py
__init__(mapping: HunkTargetMapping, **kwargs) -> None
¶Initialize hunk mapping widget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mapping
|
HunkTargetMapping
|
The hunk to commit mapping to display |
required |
compose() -> ComposeResult
¶Compose the widget layout.
Source code in src/git_autosquash/tui/widgets.py
on_click(event: events.Click) -> None
¶on_checkbox_changed(event: Checkbox.Changed) -> None
¶Handle checkbox changes.
Source code in src/git_autosquash/tui/widgets.py
DiffViewer
¶
Bases: Widget
Widget for displaying diff content with syntax highlighting.
Source code in src/git_autosquash/tui/widgets.py
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 |
|
__init__(**kwargs) -> None
¶compose() -> ComposeResult
¶show_hunk(hunk: DiffHunk) -> None
¶Display diff content for a hunk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hunk
|
DiffHunk
|
The hunk to display |
required |
Source code in src/git_autosquash/tui/widgets.py
ProgressIndicator
¶
Bases: Widget
Widget showing progress through hunk approvals.
Source code in src/git_autosquash/tui/widgets.py
__init__(total_hunks: int, **kwargs) -> None
¶Initialize progress indicator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total_hunks
|
int
|
Total number of hunks to process |
required |
Source code in src/git_autosquash/tui/widgets.py
compose() -> ComposeResult
¶update_progress(approved_count: int, ignored_count: int = 0) -> None
¶Update the progress display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
approved_count
|
int
|
Number of hunks approved so far |
required |
ignored_count
|
int
|
Number of hunks ignored so far |
0
|
Source code in src/git_autosquash/tui/widgets.py
Usage Examples¶
Basic API Usage¶
Here's how to use the core components programmatically:
from git_autosquash.git_ops import GitOps
from git_autosquash.hunk_parser import HunkParser
from git_autosquash.blame_analyzer import BlameAnalyzer
# Initialize components
git_ops = GitOps(".")
hunk_parser = HunkParser(git_ops)
blame_analyzer = BlameAnalyzer(git_ops, "main")
# Get diff hunks
hunks = hunk_parser.get_diff_hunks()
# Analyze hunks to find target commits
mappings = blame_analyzer.analyze_hunks(hunks)
# Print results
for mapping in mappings:
print(f"{mapping.hunk.file_path}: {mapping.target_commit} ({mapping.confidence})")
Custom TUI Integration¶
from git_autosquash.tui.app import AutoSquashApp
# Create custom TUI with your mappings
app = AutoSquashApp(mappings)
approved = app.run()
if approved and app.approved_mappings:
print(f"User approved {len(app.approved_mappings)} hunks")
# Process approved mappings...
Rebase Execution¶
from git_autosquash.rebase_manager import RebaseManager, RebaseConflictError
try:
rebase_manager = RebaseManager(git_ops, merge_base)
success = rebase_manager.execute_squash(approved_mappings)
if success:
print("Squash operation completed successfully!")
else:
print("Operation was cancelled by user")
except RebaseConflictError as e:
print(f"Conflicts in: {', '.join(e.conflicted_files)}")
# Handle conflicts...
Type Definitions¶
Common Types¶
from typing import List, Dict, Optional, Set
# Confidence levels
ConfidenceLevel = Literal["high", "medium", "low"]
# Working tree status
WorkingTreeStatus = Dict[str, bool] # {"is_clean": bool, "has_staged": bool, "has_unstaged": bool}
# Rebase status information
RebaseStatus = Dict[str, Any] # {"in_progress": bool, "conflicted_files": List[str], ...}
Error Types¶
All components raise specific exception types for different error conditions:
- GitOps:
subprocess.SubprocessError
for Git command failures - HunkParser:
ValueError
for parsing errors - BlameAnalyzer:
subprocess.SubprocessError
for blame failures - RebaseManager:
RebaseConflictError
for merge conflicts - TUI: Standard Textual exceptions for interface errors
Configuration Options¶
Environment Variables¶
git-autosquash respects these environment variables:
GIT_SEQUENCE_EDITOR
: Custom editor for interactive rebase (automatically managed)TERM
: Terminal type for TUI renderingNO_COLOR
: Disable colored output when set
Git Configuration¶
The following Git configuration affects git-autosquash behavior:
core.editor
: Default editor for conflict resolutionmerge.tool
: Merge tool for resolving conflictsrebase.autoStash
: Automatic stashing during rebase (overridden by git-autosquash)
Performance Considerations¶
Caching¶
Several operations are cached for performance:
- Branch commits: Expensive
git rev-list
operations - Commit timestamps:
git show
calls for chronological ordering - Commit summaries:
git log
output for display
Memory Usage¶
- Diff parsing: Streams large diffs to avoid memory issues
- Blame analysis: Processes hunks individually to limit memory usage
- TUI rendering: Efficient widget updates and syntax highlighting
Git Operation Optimization¶
- Batch operations: Groups related Git commands where possible
- Subprocess management: Proper timeout and resource cleanup
- Working directory: Minimal file I/O and temporary file usage
Testing the API¶
The API components are extensively tested. To run tests for specific components:
# Test specific components
uv run pytest tests/test_git_ops.py -v
uv run pytest tests/test_hunk_parser.py -v
uv run pytest tests/test_blame_analyzer.py -v
uv run pytest tests/test_rebase_manager.py -v
# Test with coverage
uv run pytest --cov=git_autosquash tests/
Contributing to the API¶
When extending the API:
- Follow existing patterns: Maintain consistency with current design
- Add comprehensive docstrings: Use Google style docstrings
- Include type annotations: Full typing for all public methods
- Write tests: Unit tests with appropriate mocking
- Update documentation: This reference updates automatically from docstrings