oops: fixed git reset usage
[ugit.git] / ugit / controllers / push.py
blob4010109ab2ddc27615e379d2447559111285cefe
1 import os
2 from PyQt4.QtGui import QDialog
4 from ugit import utils
5 from ugit import qtutils
6 from ugit.views import PushView
7 from ugit.qobserver import QObserver
9 def push_branches(model, parent):
10 model = model.clone()
11 view = PushView(parent)
12 controller = PushController(model, view)
13 view.show()
14 return view.exec_() == QDialog.Accepted
16 class PushController(QObserver):
17 def __init__(self, model, view):
18 QObserver.__init__(self,model,view)
20 self.add_observables(
21 'remote',
22 'remotes',
23 'local_branch',
24 'local_branches',
25 'remote_branch',
26 'remote_branches',
29 self.add_actions(remotes = self.display_remotes)
30 self.add_callbacks(
31 remotes = self.update_remotes,
32 local_branches = self.update_local_branches,
33 remote_branches = self.update_remote_branches,
34 push_button = self.push_to_remote_branch,
36 self.refresh_view()
38 def display_remotes(self, widget):
39 displayed = []
40 for remote in self.model.get_remotes():
41 url = self.model.remote_url(remote)
42 display = '%s\t(%s %s)' \
43 % (remote, unicode(self.tr('URL:')), url)
44 displayed.append(display)
45 qtutils.set_items(widget,displayed)
47 def push_to_remote_branch(self):
48 if not self.model.get_remote():
49 errmsg = self.tr('No repository selected.')
50 qtutils.show_output(errmsg)
51 return
53 if not self.model.get_remote_branch():
54 errmsg = self.tr('Please supply a branch name.')
55 qtutils.show_output(errmsg)
56 return
58 if not self.model.get_local_branch():
59 msg = self.tr('Pushing with an empty local branch '
60 + 'will remove the remote branch.\n'
61 + 'Continue?')
62 if not qtutils.question(self.view, self.tr('warning'), msg):
63 return
65 remote = self.model.get_remote()
66 local_branch = self.model.get_local_branch()
67 remote_branch = self.model.get_remote_branch()
68 ffwd = self.view.ffwd_only_checkbox.isChecked()
69 tags = self.view.tags_checkbox.isChecked()
71 status, output = self.model.push_helper(
72 remote,
73 local_branch,
74 remote_branch,
75 ffwd=ffwd,
76 tags=tags
78 qtutils.show_output(output)
79 if not status:
80 self.view.accept()
82 def update_remotes(self,*rest):
83 widget = self.view.remotes
84 remotes = self.model.get_remotes()
85 selection = qtutils.get_selected_item(widget,remotes)
86 if not selection: return
87 self.model.set_remote(selection)
88 self.view.remote.selectAll()
90 def update_local_branches(self,*rest):
91 branches = self.model.get_local_branches()
92 widget = self.view.local_branches
93 selection = qtutils.get_selected_item(widget,branches)
94 if not selection: return
96 self.model.set_local_branch(selection)
97 self.model.set_remote_branch(selection)
99 self.view.local_branch.selectAll()
100 self.view.remote_branch.selectAll()
102 def update_remote_branches(self,*rest):
103 widget = self.view.remote_branches
104 branches = self.model.get_remote_branches()
105 selection = qtutils.get_selected_item(widget,branches)
106 if not selection: return
108 branch = utils.basename(selection)
109 if branch == 'HEAD': return
110 self.model.set_remote_branch(branch)
111 self.view.remote_branch.selectAll()