-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_integration.py
50 lines (41 loc) · 1.89 KB
/
git_integration.py
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
46
47
48
49
50
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit, QInputDialog
import subprocess
class GitIntegration(QWidget):
def __init__(self, main_window):
super().__init__()
self.main_window = main_window
layout = QVBoxLayout()
self.output = QTextEdit()
self.output.setReadOnly(True)
layout.addWidget(self.output)
init_button = QPushButton("Initialize Git Repository")
init_button.clicked.connect(self.init_repo)
layout.addWidget(init_button)
commit_button = QPushButton("Commit Changes")
commit_button.clicked.connect(self.commit_changes)
layout.addWidget(commit_button)
push_button = QPushButton("Push Changes")
push_button.clicked.connect(self.push_changes)
layout.addWidget(push_button)
self.setLayout(layout)
def init_repo(self):
try:
result = subprocess.run(['git', 'init'], capture_output=True, text=True)
self.output.setPlainText(result.stdout + result.stderr)
except Exception as e:
self.output.setPlainText(f"Error: {str(e)}")
def commit_changes(self):
message, ok = QInputDialog.getText(self, "Commit Message", "Enter commit message:")
if ok and message:
try:
subprocess.run(['git', 'add', '.'], check=True)
result = subprocess.run(['git', 'commit', '-m', message], capture_output=True, text=True)
self.output.setPlainText(result.stdout + result.stderr)
except Exception as e:
self.output.setPlainText(f"Error: {str(e)}")
def push_changes(self):
try:
result = subprocess.run(['git', 'push'], capture_output=True, text=True)
self.output.setPlainText(result.stdout + result.stderr)
except Exception as e:
self.output.setPlainText(f"Error: {str(e)}")