src/eric7/Plugins/VcsPlugins/vcsGit/GitPushDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class GitPushDialog(QDialog, Ui_GitPushDialog): 16 class GitPushDialog(QDialog, Ui_GitPushDialog):
17 """ 17 """
18 Class implementing a dialog to enter data for a Push operation. 18 Class implementing a dialog to enter data for a Push operation.
19 """ 19 """
20
20 PushColumn = 0 21 PushColumn = 0
21 LocalBranchColumn = 1 22 LocalBranchColumn = 1
22 RemoteBranchColumn = 2 23 RemoteBranchColumn = 2
23 ForceColumn = 3 24 ForceColumn = 3
24 25
25 def __init__(self, vcs, repodir, parent=None): 26 def __init__(self, vcs, repodir, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param vcs reference to the git object 30 @param vcs reference to the git object
30 @param repodir directory name of the local repository (string) 31 @param repodir directory name of the local repository (string)
31 @param parent reference to the parent widget (QWidget) 32 @param parent reference to the parent widget (QWidget)
32 """ 33 """
33 super().__init__(parent) 34 super().__init__(parent)
34 self.setupUi(self) 35 self.setupUi(self)
35 36
36 self.__vcs = vcs 37 self.__vcs = vcs
37 self.__repodir = repodir 38 self.__repodir = repodir
38 39
39 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir) 40 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir)
40 self.__repos = {name: url for name, url in remoteUrlsList} 41 self.__repos = {name: url for name, url in remoteUrlsList}
41 42
42 remoteBranches = self.__vcs.gitGetBranchesList(self.__repodir, 43 remoteBranches = self.__vcs.gitGetBranchesList(self.__repodir, remotes=True)
43 remotes=True)
44 self.__remotes = {} 44 self.__remotes = {}
45 for remoteBranch in remoteBranches: 45 for remoteBranch in remoteBranches:
46 repo, branch = remoteBranch.rsplit("/", 2)[-2:] 46 repo, branch = remoteBranch.rsplit("/", 2)[-2:]
47 if repo not in self.__remotes: 47 if repo not in self.__remotes:
48 self.__remotes[repo] = [] 48 self.__remotes[repo] = []
49 self.__remotes[repo].append(branch) 49 self.__remotes[repo].append(branch)
50 50
51 self.__localBranches = self.__vcs.gitGetBranchesList(self.__repodir, 51 self.__localBranches = self.__vcs.gitGetBranchesList(
52 withMaster=True) 52 self.__repodir, withMaster=True
53 53 )
54
54 self.remotesComboBox.addItems(sorted(self.__repos.keys())) 55 self.remotesComboBox.addItems(sorted(self.__repos.keys()))
55 56
56 for localBranch in self.__localBranches: 57 for localBranch in self.__localBranches:
57 itm = QTreeWidgetItem(self.branchesTree, ["", localBranch, "", ""]) 58 itm = QTreeWidgetItem(self.branchesTree, ["", localBranch, "", ""])
58 combo = QComboBox() 59 combo = QComboBox()
59 combo.setEditable(True) 60 combo.setEditable(True)
60 combo.setSizeAdjustPolicy( 61 combo.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
61 QComboBox.SizeAdjustPolicy.AdjustToContents)
62 self.branchesTree.setItemWidget( 62 self.branchesTree.setItemWidget(
63 itm, GitPushDialog.RemoteBranchColumn, combo) 63 itm, GitPushDialog.RemoteBranchColumn, combo
64 64 )
65
65 self.__resizeColumns() 66 self.__resizeColumns()
66 67
67 self.branchesTree.header().setSortIndicator( 68 self.branchesTree.header().setSortIndicator(
68 GitPushDialog.LocalBranchColumn, Qt.SortOrder.AscendingOrder) 69 GitPushDialog.LocalBranchColumn, Qt.SortOrder.AscendingOrder
69 70 )
71
70 self.forceWarningLabel.setVisible(False) 72 self.forceWarningLabel.setVisible(False)
71 73
72 index = self.remotesComboBox.findText("origin") 74 index = self.remotesComboBox.findText("origin")
73 if index == -1: 75 if index == -1:
74 index = 0 76 index = 0
75 self.remotesComboBox.setCurrentIndex(index) 77 self.remotesComboBox.setCurrentIndex(index)
76 78
77 def __resizeColumns(self): 79 def __resizeColumns(self):
78 """ 80 """
79 Private slot to adjust the column sizes. 81 Private slot to adjust the column sizes.
80 """ 82 """
81 for col in range(self.branchesTree.columnCount()): 83 for col in range(self.branchesTree.columnCount()):
82 self.branchesTree.resizeColumnToContents(col) 84 self.branchesTree.resizeColumnToContents(col)
83 85
84 @pyqtSlot(str) 86 @pyqtSlot(str)
85 def on_remotesComboBox_currentTextChanged(self, txt): 87 def on_remotesComboBox_currentTextChanged(self, txt):
86 """ 88 """
87 Private slot to handle changes of the selected repository. 89 Private slot to handle changes of the selected repository.
88 90
89 @param txt current text of the combo box (string) 91 @param txt current text of the combo box (string)
90 """ 92 """
91 self.remoteEdit.setText(self.__repos[txt]) 93 self.remoteEdit.setText(self.__repos[txt])
92 94
93 for row in range(self.branchesTree.topLevelItemCount()): 95 for row in range(self.branchesTree.topLevelItemCount()):
94 itm = self.branchesTree.topLevelItem(row) 96 itm = self.branchesTree.topLevelItem(row)
95 localBranch = itm.text(GitPushDialog.LocalBranchColumn) 97 localBranch = itm.text(GitPushDialog.LocalBranchColumn)
96 combo = self.branchesTree.itemWidget( 98 combo = self.branchesTree.itemWidget(itm, GitPushDialog.RemoteBranchColumn)
97 itm, GitPushDialog.RemoteBranchColumn)
98 combo.clear() 99 combo.clear()
99 combo.addItems([""] + sorted(self.__remotes[txt])) 100 combo.addItems([""] + sorted(self.__remotes[txt]))
100 index = combo.findText(localBranch) 101 index = combo.findText(localBranch)
101 if index != -1: 102 if index != -1:
102 combo.setCurrentIndex(index) 103 combo.setCurrentIndex(index)
103 itm.setCheckState(GitPushDialog.PushColumn, 104 itm.setCheckState(GitPushDialog.PushColumn, Qt.CheckState.Checked)
104 Qt.CheckState.Checked)
105 else: 105 else:
106 itm.setCheckState(GitPushDialog.PushColumn, 106 itm.setCheckState(GitPushDialog.PushColumn, Qt.CheckState.Unchecked)
107 Qt.CheckState.Unchecked) 107 itm.setCheckState(GitPushDialog.ForceColumn, Qt.CheckState.Unchecked)
108 itm.setCheckState(GitPushDialog.ForceColumn, 108
109 Qt.CheckState.Unchecked)
110
111 self.__resizeColumns() 109 self.__resizeColumns()
112 110
113 @pyqtSlot(QTreeWidgetItem, int) 111 @pyqtSlot(QTreeWidgetItem, int)
114 def on_branchesTree_itemChanged(self, item, column): 112 def on_branchesTree_itemChanged(self, item, column):
115 """ 113 """
116 Private slot handling changes of a branch item. 114 Private slot handling changes of a branch item.
117 115
118 @param item reference to the changed item (QTreeWidgetItem) 116 @param item reference to the changed item (QTreeWidgetItem)
119 @param column changed column (integer) 117 @param column changed column (integer)
120 """ 118 """
121 if column == GitPushDialog.PushColumn: 119 if column == GitPushDialog.PushColumn:
122 # step 1: set the item's remote branch, if it is empty 120 # step 1: set the item's remote branch, if it is empty
123 if ( 121 if item.checkState(GitPushDialog.PushColumn) == Qt.CheckState.Checked and (
124 item.checkState(GitPushDialog.PushColumn) == 122 self.branchesTree.itemWidget(
125 Qt.CheckState.Checked and 123 item, GitPushDialog.RemoteBranchColumn
126 (self.branchesTree.itemWidget( 124 ).currentText()
127 item, 125 == ""
128 GitPushDialog.RemoteBranchColumn
129 ).currentText() == "")
130 ): 126 ):
131 self.branchesTree.itemWidget( 127 self.branchesTree.itemWidget(
132 item, GitPushDialog.RemoteBranchColumn).setEditText( 128 item, GitPushDialog.RemoteBranchColumn
133 item.text(GitPushDialog.LocalBranchColumn)) 129 ).setEditText(item.text(GitPushDialog.LocalBranchColumn))
134 130
135 # step 2: count checked items 131 # step 2: count checked items
136 checkedItemsCount = 0 132 checkedItemsCount = 0
137 for row in range(self.branchesTree.topLevelItemCount()): 133 for row in range(self.branchesTree.topLevelItemCount()):
138 itm = self.branchesTree.topLevelItem(row) 134 itm = self.branchesTree.topLevelItem(row)
139 if ( 135 if itm.checkState(GitPushDialog.PushColumn) == Qt.CheckState.Checked:
140 itm.checkState(GitPushDialog.PushColumn) ==
141 Qt.CheckState.Checked
142 ):
143 checkedItemsCount += 1 136 checkedItemsCount += 1
144 if checkedItemsCount == len(self.__localBranches): 137 if checkedItemsCount == len(self.__localBranches):
145 self.selectAllCheckBox.setCheckState(Qt.CheckState.Checked) 138 self.selectAllCheckBox.setCheckState(Qt.CheckState.Checked)
146 elif checkedItemsCount == 0: 139 elif checkedItemsCount == 0:
147 self.selectAllCheckBox.setCheckState(Qt.CheckState.Unchecked) 140 self.selectAllCheckBox.setCheckState(Qt.CheckState.Unchecked)
148 else: 141 else:
149 self.selectAllCheckBox.setCheckState( 142 self.selectAllCheckBox.setCheckState(Qt.CheckState.PartiallyChecked)
150 Qt.CheckState.PartiallyChecked) 143
151
152 elif column == GitPushDialog.ForceColumn: 144 elif column == GitPushDialog.ForceColumn:
153 forceItemsCount = 0 145 forceItemsCount = 0
154 for row in range(self.branchesTree.topLevelItemCount()): 146 for row in range(self.branchesTree.topLevelItemCount()):
155 itm = self.branchesTree.topLevelItem(row) 147 itm = self.branchesTree.topLevelItem(row)
156 if ( 148 if itm.checkState(GitPushDialog.ForceColumn) == Qt.CheckState.Checked:
157 itm.checkState(GitPushDialog.ForceColumn) ==
158 Qt.CheckState.Checked
159 ):
160 forceItemsCount += 1 149 forceItemsCount += 1
161 self.forceWarningLabel.setVisible(forceItemsCount > 0) 150 self.forceWarningLabel.setVisible(forceItemsCount > 0)
162 151
163 @pyqtSlot(int) 152 @pyqtSlot(int)
164 def on_selectAllCheckBox_stateChanged(self, state): 153 def on_selectAllCheckBox_stateChanged(self, state):
165 """ 154 """
166 Private slot to select/deselect all branch items. 155 Private slot to select/deselect all branch items.
167 156
168 @param state check state of the check box (Qt.CheckState) 157 @param state check state of the check box (Qt.CheckState)
169 """ 158 """
170 if state != Qt.CheckState.PartiallyChecked: 159 if state != Qt.CheckState.PartiallyChecked:
171 for row in range(self.branchesTree.topLevelItemCount()): 160 for row in range(self.branchesTree.topLevelItemCount()):
172 itm = self.branchesTree.topLevelItem(row) 161 itm = self.branchesTree.topLevelItem(row)
173 if itm.checkState(GitPushDialog.PushColumn) != state: 162 if itm.checkState(GitPushDialog.PushColumn) != state:
174 itm.setCheckState(GitPushDialog.PushColumn, state) 163 itm.setCheckState(GitPushDialog.PushColumn, state)
175 164
176 def getData(self): 165 def getData(self):
177 """ 166 """
178 Public method to get the entered data. 167 Public method to get the entered data.
179 168
180 @return remote name, list of branches to be pushed, 169 @return remote name, list of branches to be pushed,
181 a flag indicating to push tags as well, a flag indicating 170 a flag indicating to push tags as well, a flag indicating
182 to set tracking information and the push method for submodules 171 to set tracking information and the push method for submodules
183 @rtype tuple of (str, list of str, bool, bool, str) 172 @rtype tuple of (str, list of str, bool, bool, str)
184 """ 173 """
185 refspecs = [] 174 refspecs = []
186 for row in range(self.branchesTree.topLevelItemCount()): 175 for row in range(self.branchesTree.topLevelItemCount()):
187 itm = self.branchesTree.topLevelItem(row) 176 itm = self.branchesTree.topLevelItem(row)
188 force = ( 177 force = itm.checkState(GitPushDialog.ForceColumn) == Qt.CheckState.Checked
189 itm.checkState(GitPushDialog.ForceColumn) == 178 if itm.checkState(GitPushDialog.PushColumn) == Qt.CheckState.Checked:
190 Qt.CheckState.Checked
191 )
192 if (
193 itm.checkState(GitPushDialog.PushColumn) ==
194 Qt.CheckState.Checked
195 ):
196 localBranch = itm.text(GitPushDialog.LocalBranchColumn) 179 localBranch = itm.text(GitPushDialog.LocalBranchColumn)
197 remoteBranch = self.branchesTree.itemWidget( 180 remoteBranch = self.branchesTree.itemWidget(
198 itm, GitPushDialog.RemoteBranchColumn).currentText() 181 itm, GitPushDialog.RemoteBranchColumn
199 refspecs.append("{0}{1}:{2}".format( 182 ).currentText()
200 "+" if force else "", localBranch, remoteBranch)) 183 refspecs.append(
201 184 "{0}{1}:{2}".format("+" if force else "", localBranch, remoteBranch)
185 )
186
202 # submodule stuff (--recurse-submodules=) 187 # submodule stuff (--recurse-submodules=)
203 if self.submodulesOnDemandButton.isChecked(): 188 if self.submodulesOnDemandButton.isChecked():
204 submodulesPush = "on-demand" 189 submodulesPush = "on-demand"
205 elif self.submodulesCheckButton.isChecked(): 190 elif self.submodulesCheckButton.isChecked():
206 submodulesPush = "check" 191 submodulesPush = "check"
207 elif self.submodulesOnlyButton.isChecked(): 192 elif self.submodulesOnlyButton.isChecked():
208 submodulesPush = "only" 193 submodulesPush = "only"
209 else: 194 else:
210 submodulesPush = "no" 195 submodulesPush = "no"
211 196
212 return ( 197 return (
213 self.remotesComboBox.currentText(), 198 self.remotesComboBox.currentText(),
214 refspecs, 199 refspecs,
215 self.tagsCheckBox.isChecked(), 200 self.tagsCheckBox.isChecked(),
216 self.trackingCheckBox.isChecked(), 201 self.trackingCheckBox.isChecked(),

eric ide

mercurial