-
-
Notifications
You must be signed in to change notification settings - Fork 770
Expand file tree
/
Copy pathgit_integration_example.py
More file actions
45 lines (36 loc) · 1.19 KB
/
git_integration_example.py
File metadata and controls
45 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
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
"""
Git Integration Example for PraisonAI CLI.
Auto-commit with AI messages, diff viewing, undo.
Docs: https://docs.praison.ai/cli/git-integration
"""
from praisonai.cli.features import GitIntegrationHandler
# Initialize
handler = GitIntegrationHandler(output="verbose")
git = handler.initialize(repo_path=".")
# Check if it's a git repo
if not git.is_repo:
print("Not a git repository!")
exit(1)
# Show status
print("=== Git Status ===")
status = handler.show_status()
print(f"Branch: {status.branch}")
print(f"Staged: {len(status.staged_files)}")
print(f"Modified: {len(status.modified_files)}")
print(f"Untracked: {len(status.untracked_files)}")
# Show diff (if any changes)
if status.has_changes:
print("\n=== Diff ===")
diff = handler.show_diff()
if diff:
print(diff[:300] + "..." if len(diff) > 300 else diff)
# Show recent commits
print("\n=== Recent Commits ===")
commits = handler.show_log(count=5)
for c in commits:
print(f" {c.short_hash} {c.message[:50]}")
# To commit with AI message:
# commit = handler.commit() # Auto-generates message
# commit = handler.commit(message="Custom message")
# To undo last commit:
# handler.undo(soft=True) # Keeps changes staged