修改了settings.py丢失的bug
This commit is contained in:
@@ -188,6 +188,15 @@ class RemoteCommandsTab(QWidget):
|
||||
self.clone_button = QPushButton("克隆项目")
|
||||
self.clone_button.clicked.connect(self.clone_repository)
|
||||
right_layout.addWidget(self.clone_button)
|
||||
|
||||
self.pull_button = QPushButton("拉取更新")
|
||||
self.pull_button.clicked.connect(self.pull_repository)
|
||||
right_layout.addWidget(self.pull_button)
|
||||
|
||||
self.handle_changes_button = QPushButton("处理本地更改")
|
||||
self.handle_changes_button.clicked.connect(self.handle_local_changes)
|
||||
right_layout.addWidget(self.handle_changes_button)
|
||||
|
||||
right_layout.addStretch()
|
||||
|
||||
clone_layout.addLayout(right_layout)
|
||||
@@ -425,6 +434,140 @@ class RemoteCommandsTab(QWidget):
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(self.on_command_finished)
|
||||
self.command_thread.start()
|
||||
|
||||
def pull_repository(self):
|
||||
logger.info("拉取仓库更新")
|
||||
|
||||
if not self.ssh_client:
|
||||
QMessageBox.warning(self, "警告", "请先连接到服务器")
|
||||
return
|
||||
|
||||
remote_dir = self.remote_dir_display.text().strip()
|
||||
if not remote_dir:
|
||||
QMessageBox.warning(self, "警告", "请先设置远程目录")
|
||||
return
|
||||
|
||||
# 从仓库URL中提取项目名称
|
||||
repo_url = self.repo_url_input.text().strip()
|
||||
if not repo_url:
|
||||
QMessageBox.warning(self, "警告", "请输入仓库URL")
|
||||
return
|
||||
|
||||
# 从URL中提取项目名(例如:http://example.com/repo.git -> repo)
|
||||
project_name = repo_url.split('/')[-1].replace('.git', '')
|
||||
project_path = f"{remote_dir}/{project_name}"
|
||||
|
||||
self.output_text.clear()
|
||||
self.status_label.setText("正在拉取仓库更新...")
|
||||
|
||||
# 构建拉取命令
|
||||
pull_command = f"cd {project_path} && git pull --verbose"
|
||||
|
||||
# 创建并启动线程执行命令
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, pull_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(self.on_command_finished)
|
||||
self.command_thread.start()
|
||||
|
||||
def handle_local_changes(self):
|
||||
logger.info("处理本地更改")
|
||||
|
||||
if not self.ssh_client:
|
||||
QMessageBox.warning(self, "警告", "请先连接到服务器")
|
||||
return
|
||||
|
||||
remote_dir = self.remote_dir_display.text().strip()
|
||||
if not remote_dir:
|
||||
QMessageBox.warning(self, "警告", "请先设置远程目录")
|
||||
return
|
||||
|
||||
# 从仓库URL中提取项目名称
|
||||
repo_url = self.repo_url_input.text().strip()
|
||||
if not repo_url:
|
||||
QMessageBox.warning(self, "警告", "请输入仓库URL")
|
||||
return
|
||||
|
||||
# 从URL中提取项目名(例如:http://example.com/repo.git -> repo)
|
||||
project_name = repo_url.split('/')[-1].replace('.git', '')
|
||||
project_path = f"{remote_dir}/{project_name}"
|
||||
|
||||
self.output_text.clear()
|
||||
self.status_label.setText("正在检查本地更改...")
|
||||
|
||||
# 创建对话框询问用户如何处理本地更改
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"处理本地更改",
|
||||
"检测到本地有未提交的更改,请选择处理方式:\n\n"
|
||||
"是(Y) - 暂存更改(stash),拉取更新后再恢复\n"
|
||||
"否(N) - 放弃本地更改,直接拉取更新\n"
|
||||
"取消 - 取消操作",
|
||||
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
|
||||
QMessageBox.Cancel
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
# 暂存更改
|
||||
self.status_label.setText("正在暂存更改...")
|
||||
stash_command = f"cd {project_path} && git stash push -m 'Auto-stash before pull'"
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, stash_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(lambda success, msg: self.on_stash_finished(success, msg, project_path))
|
||||
self.command_thread.start()
|
||||
elif reply == QMessageBox.No:
|
||||
# 放弃本地更改,强制拉取
|
||||
self.status_label.setText("正在重置本地更改...")
|
||||
reset_command = f"cd {project_path} && git reset --hard HEAD && git clean -fd"
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, reset_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(lambda success, msg: self.on_reset_finished(success, msg, project_path))
|
||||
self.command_thread.start()
|
||||
# 如果选择取消,不做任何操作
|
||||
|
||||
def on_stash_finished(self, success, message, project_path):
|
||||
"""暂存操作完成后的处理"""
|
||||
if success:
|
||||
self.append_output("暂存更改成功,正在拉取更新...")
|
||||
# 拉取更新
|
||||
pull_command = f"cd {project_path} && git pull --verbose"
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, pull_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(lambda success, msg: self.on_pull_after_stash_finished(success, msg, project_path))
|
||||
self.command_thread.start()
|
||||
else:
|
||||
self.status_label.setText("暂存更改失败")
|
||||
self.status_label.setStyleSheet("color: red;")
|
||||
self.append_output(f"暂存更改失败: {message}")
|
||||
|
||||
def on_pull_after_stash_finished(self, success, message, project_path):
|
||||
"""暂存后拉取更新完成后的处理"""
|
||||
if success:
|
||||
self.append_output("拉取更新成功,正在恢复暂存的更改...")
|
||||
# 恢复暂存的更改
|
||||
pop_command = f"cd {project_path} && git stash pop"
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, pop_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(self.on_command_finished)
|
||||
self.command_thread.start()
|
||||
else:
|
||||
self.status_label.setText("拉取更新失败")
|
||||
self.status_label.setStyleSheet("color: red;")
|
||||
self.append_output(f"拉取更新失败: {message}")
|
||||
|
||||
def on_reset_finished(self, success, message, project_path):
|
||||
"""重置操作完成后的处理"""
|
||||
if success:
|
||||
self.append_output("重置本地更改成功,正在拉取更新...")
|
||||
# 拉取更新
|
||||
pull_command = f"cd {project_path} && git pull --verbose"
|
||||
self.command_thread = RemoteCommandThread(self.ssh_client, pull_command)
|
||||
self.command_thread.output_signal.connect(self.append_output)
|
||||
self.command_thread.finished_signal.connect(self.on_command_finished)
|
||||
self.command_thread.start()
|
||||
else:
|
||||
self.status_label.setText("重置本地更改失败")
|
||||
self.status_label.setStyleSheet("color: red;")
|
||||
self.append_output(f"重置本地更改失败: {message}")
|
||||
|
||||
def append_output(self, text):
|
||||
self.output_text.append(text)
|
||||
|
||||
Reference in New Issue
Block a user