def action_callback(self): action = self.action if action == FETCH: model_action = self.model.fetch elif action == PUSH: model_action = self.push_to_all else: # if action == PULL: model_action = self.model.pull remote_name = ustr(self.remote_name.text()) if not remote_name: errmsg = N_("No repository selected.") Interaction.log(errmsg) return remote, kwargs = self.common_args() self.selected_remotes = qtutils.selected_items(self.remotes, self.model.remotes) # Check if we're about to create a new branch and warn. remote_branch = ustr(self.remote_branch.text()) local_branch = ustr(self.local_branch.text()) if action == PUSH and not remote_branch: branch = local_branch candidate = "%s/%s" % (remote, branch) if candidate not in self.model.remote_branches: title = N_("Push") args = dict(branch=branch, remote=remote) msg = ( N_('Branch "%(branch)s" does not exist in "%(remote)s".\n' "A new remote branch will be published.") % args ) info_txt = N_("Create a new remote branch?") ok_text = N_("Create Remote Branch") if not qtutils.confirm(title, msg, info_txt, ok_text, icon=icons.cola()): return if not self.ffwd_only_checkbox.isChecked(): if action == FETCH: title = N_("Force Fetch?") msg = N_("Non-fast-forward fetch overwrites local history!") info_txt = N_("Force fetching from %s?") % remote ok_text = N_("Force Fetch") elif action == PUSH: title = N_("Force Push?") msg = N_("Non-fast-forward push overwrites published " "history!\n(Did you pull first?)") info_txt = N_("Force push to %s?") % remote ok_text = N_("Force Push") else: # pull: shouldn't happen since the controls are hidden msg = "You probably don't want to do this.\n\tContinue?" return if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=icons.discard()): return # Disable the GUI by default self.buttons.setEnabled(False) # Use a thread to update in the background task = ActionTask(self.task_runner, model_action, remote, kwargs) self.task_runner.start(task, progress=self.progress, finish=self.action_completed)
def commit(self): """Attempt to create a commit from the index and commit message.""" if not bool(self.summary.value()): # Describe a good commit message error_msg = N_( "" "Please supply a commit message.\n\n" "A good commit message has the following format:\n\n" "- First line: Describe in one sentence what you did.\n" "- Second line: Blank\n" "- Remaining lines: Describe why this change is good.\n" ) Interaction.log(error_msg) Interaction.information(N_("Missing Commit Message"), error_msg) return msg = self.commit_message(raw=False) if not self.model.staged: error_msg = N_("" "No changes to commit.\n\n" "You must stage at least 1 file before you can commit.") if self.model.modified: informative_text = N_("Would you like to stage and " "commit all modified files?") if not qtutils.confirm( N_("Stage and commit?"), error_msg, informative_text, N_("Stage and Commit"), default=True, icon=qtutils.save_icon(), ): return else: Interaction.information(N_("Nothing to commit"), error_msg) return cmds.do(cmds.StageModified) # Warn that amending published commits is generally bad amend = self.amend_action.isChecked() if ( amend and self.model.is_commit_published() and not qtutils.confirm( N_("Rewrite Published Commit?"), N_( "This commit has already been published.\n" "This operation will rewrite published history.\n" "You probably don't want to do this." ), N_("Amend the published commit?"), N_("Amend Commit"), default=False, icon=qtutils.save_icon(), ) ): return no_verify = self.bypass_commit_hooks_action.isChecked() sign = self.sign_action.isChecked() status, out, err = cmds.do(cmds.Commit, amend, msg, sign, no_verify=no_verify) if status != 0: Interaction.critical(N_("Commit failed"), N_('"git commit" returned exit code %s') % (status,), out + err)
def commit(self): """Attempt to create a commit from the index and commit message.""" if not bool(self.summary.value()): # Describe a good commit message error_msg = N_( 'Please supply a commit message.\n\n' 'A good commit message has the following format:\n\n' '- First line: Describe in one sentence what you did.\n' '- Second line: Blank\n' '- Remaining lines: Describe why this change is good.\n') Interaction.log(error_msg) Interaction.information(N_('Missing Commit Message'), error_msg) return msg = self.commit_message(raw=False) if not self.model.staged: error_msg = N_( 'No changes to commit.\n\n' 'You must stage at least 1 file before you can commit.') if self.model.modified: informative_text = N_('Would you like to stage and ' 'commit all modified files?') if not qtutils.confirm(N_('Stage and commit?'), error_msg, informative_text, N_('Stage and Commit'), default=True, icon=icons.save()): return else: Interaction.information(N_('Nothing to commit'), error_msg) return cmds.do(cmds.StageModified) # Warn that amending published commits is generally bad amend = self.amend_action.isChecked() if (amend and self.model.is_commit_published() and not qtutils.confirm( N_('Rewrite Published Commit?'), N_('This commit has already been published.\n' 'This operation will rewrite published history.\n' 'You probably don\'t want to do this.'), N_('Amend the published commit?'), N_('Amend Commit'), default=False, icon=icons.save())): return no_verify = self.bypass_commit_hooks_action.isChecked() sign = self.sign_action.isChecked() status, out, err = cmds.do(cmds.Commit, amend, msg, sign, no_verify=no_verify) if status != 0: Interaction.critical( N_('Commit failed'), N_('"git commit" returned exit code %s') % (status, ), out + err)
def remote_callback(): if not self.model.remotename: errmsg = self.tr('No repository selected.') qtutils.log(1, errmsg) return remote, kwargs = self.common_args() action = self.action # Check if we're about to create a new branch and warn. if action == 'push' and not self.model.remote_branch: branch = self.model.local_branch candidate = '%s/%s' % (remote, branch) if candidate not in self.model.remote_branches: title = 'Push' msg = 'Branch "%s" does not exist in %s.' % (branch, remote) msg += '\nA new remote branch will be published.' info_txt= 'Create a new remote branch?' ok_text = 'Create Remote Branch' if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=qtutils.git_icon()): return if not self.model.ffwd_only_checkbox: title = 'Force %s?' % action.title() ok_text = 'Force %s' % action.title() if action == 'fetch': msg = 'Non-fast-forward fetch overwrites local history!' info_txt = 'Force fetching from %s?' % remote elif action == 'push': msg = ('Non-fast-forward push overwrites published ' 'history!\n(Did you pull first?)') info_txt = 'Force push to %s?' % remote else: # pull: shouldn't happen since the controls are hidden msg = "You probably don't want to do this.\n\tContinue?" return if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=qtutils.discard_icon()): return # Disable the GUI by default self.view.setEnabled(False) self.progress.setEnabled(True) QtGui.QApplication.setOverrideCursor(Qt.WaitCursor) # Show a nice progress bar self.progress.setLabelText('Updating...') self.progress.show() # Use a thread to update in the background task = ActionTask(self.view, modelaction, remote, kwargs) self._tasks.append(task) QtCore.QThreadPool.globalInstance().start(task)
def commit(self): """Attempt to create a commit from the index and commit message.""" if not bool(self.summary.value()): # Describe a good commit message error_msg = tr( '' 'Please supply a commit message.\n\n' 'A good commit message has the following format:\n\n' '- First line: Describe in one sentence what you did.\n' '- Second line: Blank\n' '- Remaining lines: Describe why this change is good.\n') log(1, error_msg) cola.notifier().broadcast(signals.information, 'Missing Commit Message', error_msg) return msg = self.commit_message(raw=False) if not self.model.staged: error_msg = tr( '' 'No changes to commit.\n\n' 'You must stage at least 1 file before you can commit.') if self.model.modified: informative_text = tr('Would you like to stage and ' 'commit all modified files?') if not confirm('Stage and commit?', error_msg, informative_text, 'Stage and Commit', default=False, icon=save_icon()): return else: cola.notifier().broadcast(signals.information, 'Nothing to commit', error_msg) return cola.notifier().broadcast(signals.stage_modified) # Warn that amending published commits is generally bad amend = self.amend_action.isChecked() if (amend and self.model.is_commit_published() and not confirm('Rewrite Published Commit?', 'This commit has already been published.\n' 'This operation will rewrite published history.\n' 'You probably don\'t want to do this.', 'Amend the published commit?', 'Amend Commit', default=False, icon=save_icon())): return # Perform the commit cola.notifier().broadcast(signals.commit, amend, msg)
def commit(self): """Attempt to create a commit from the index and commit message.""" if not bool(self.summary.value()): # Describe a good commit message error_msg = tr('' 'Please supply a commit message.\n\n' 'A good commit message has the following format:\n\n' '- First line: Describe in one sentence what you did.\n' '- Second line: Blank\n' '- Remaining lines: Describe why this change is good.\n') log(1, error_msg) cola.notifier().broadcast(signals.information, 'Missing Commit Message', error_msg) return msg = self.commit_message() if not self.model.staged: error_msg = tr('' 'No changes to commit.\n\n' 'You must stage at least 1 file before you can commit.') if self.model.modified: informative_text = tr('Would you like to stage and ' 'commit all modified files?') if not confirm('Stage and commit?', error_msg, informative_text, 'Stage and Commit', default=False, icon=save_icon()): return else: cola.notifier().broadcast(signals.information, 'Nothing to commit', error_msg) return cola.notifier().broadcast(signals.stage_modified) # Warn that amending published commits is generally bad amend = self.amend_action.isChecked() if (amend and self.model.is_commit_published() and not confirm('Rewrite Published Commit?', 'This commit has already been published.\n' 'This operation will rewrite published history.\n' 'You probably don\'t want to do this.', 'Amend the published commit?', 'Amend Commit', default=False, icon=save_icon())): return # Perform the commit cola.notifier().broadcast(signals.commit, amend, msg)
def commit(self): """Attempt to create a commit from the index and commit message.""" if not bool(self.summary.value()): # Describe a good commit message error_msg = N_('' 'Please supply a commit message.\n\n' 'A good commit message has the following format:\n\n' '- First line: Describe in one sentence what you did.\n' '- Second line: Blank\n' '- Remaining lines: Describe why this change is good.\n') Interaction.log(error_msg) Interaction.information(N_('Missing Commit Message'), error_msg) return msg = self.commit_message(raw=False) if not self.model.staged: error_msg = N_('' 'No changes to commit.\n\n' 'You must stage at least 1 file before you can commit.') if self.model.modified: informative_text = N_('Would you like to stage and ' 'commit all modified files?') if not confirm(N_('Stage and commit?'), error_msg, informative_text, N_('Stage and Commit'), default=False, icon=save_icon()): return else: Interaction.information(N_('Nothing to commit'), error_msg) return cmds.do(cmds.StageModified) # Warn that amending published commits is generally bad amend = self.amend_action.isChecked() if (amend and self.model.is_commit_published() and not confirm(N_('Rewrite Published Commit?'), N_('This commit has already been published.\n' 'This operation will rewrite published history.\n' 'You probably don\'t want to do this.'), N_('Amend the published commit?'), N_('Amend Commit'), default=False, icon=save_icon())): return status, output = cmds.do(cmds.Commit, amend, msg) if status != 0: Interaction.critical(N_('Commit failed'), N_('"git commit" returned exit code %s') % (status,), output)
def _revert_unstaged_edits(self, staged=False): if not self.m.undoable(): return if staged: items_to_undo = self.staged() else: items_to_undo = self.modified() if items_to_undo: if not qtutils.confirm('Revert Unstaged Changes?', 'This operation drops unstaged changes.' '\nThese changes cannot be recovered.', 'Revert the unstaged changes?', 'Revert Unstaged Changes', default=True, icon=qtutils.icon('undo.svg')): return args = [] if not staged and self.m.amending(): args.append(self.m.head) cola.notifier().broadcast(signals.checkout, args + ['--'] + items_to_undo) else: qtutils.log(1, self.tr('No files selected for ' 'checkout from HEAD.'))
def _delete_files(self): files = self.untracked() count = len(files) if count == 0: return title = N_('Delete Files?') msg = N_('The following files will be deleted:') + '\n\n' fileinfo = subprocess.list2cmdline(files) if len(fileinfo) > 2048: fileinfo = fileinfo[:2048].rstrip() + '...' msg += fileinfo info_txt = N_('Delete %d file(s)?') % count ok_txt = N_('Delete Files') if qtutils.confirm( title, msg, info_txt, ok_txt, default=True, icon=qtutils.discard_icon()): cmds.do(cmds.Delete, files)
def remote_renamed(self, item): idx = self.remotes.row(item) if idx < 0: return if idx >= len(self.remote_list): return old_name = self.remote_list[idx] new_name = ustr(item.text()) if new_name == old_name: return if not new_name: item.setText(old_name) return title = N_('Rename Remote') question = N_('Rename remote?') info = (N_('Rename remote "%(current)s" to "%(new)s"?') % dict(current=old_name, new=new_name)) ok_btn = N_('Rename') if qtutils.confirm(title, question, info, ok_btn): status, out, err = git.remote('rename', old_name, new_name) if status == 0: self.remote_list[idx] = new_name else: item.setText(old_name)
def remote_renamed(self, item): idx = self.remotes.row(item) if idx < 0: return if idx >= len(self.remote_list): return old_name = self.remote_list[idx] new_name = unicode(item.text()) if new_name == old_name: return if not new_name: item.setText(old_name) return title = 'Rename Remote' question = 'Rename remote?' info = unicode(self.tr( 'Rename remote "%s" to "%s"?')) % (old_name, new_name) ok_btn = 'Rename' if qtutils.confirm(title, question, info, ok_btn): git.remote('rename', old_name, new_name) self.remote_list[idx] = new_name else: item.setText(old_name)
def create_tag(self): """Verifies inputs and emits a notifier tag message.""" if not self.model.tag_name: cola.notifier().broadcast(signals.critical, 'Missing Name', 'You must name the tag.') return if (self.model.sign_tag and not self.model.tag_msg and not qtutils.confirm('Missing Tag Message', 'Tag-signing was requested but the tag ' 'message is empty.', 'An unsigned, lightweight tag will be ' 'created instead.\n' 'Create an unsigned tag?', 'Create Unsigned Tag', default=False, icon=qtutils.save_icon())): return cola.notifier().broadcast(signals.tag, self.model.tag_name, self.model.revision_item, sign=self.model.sign_tag, message=self.model.tag_msg) self.view.accept()
def create_tag(self): """Verifies inputs and emits a notifier tag message.""" revision = self.revision.value() tag_name = self.tag_name.value() tag_msg = self.tag_msg.value() sign_tag = self.sign_tag.isChecked() if not revision: critical('Missing Revision', 'Please specify a revision to tag.') return elif not tag_name: critical('Missing Name', 'Please specify a name for the new tag.') return elif (sign_tag and not tag_msg and not qtutils.confirm('Missing Tag Message', 'Tag-signing was requested but the tag ' 'message is empty.', 'An unsigned, lightweight tag will be ' 'created instead.\n' 'Create an unsigned tag?', 'Create Unsigned Tag', default=False, icon=qtutils.save_icon())): return cola.notifier().broadcast(signals.tag, tag_name, revision, sign=sign_tag, message=tag_msg) information('Tag Created', 'Created a new tag named "%s"' % tag_name, details=tag_msg or None) self.accept()
def remote_renamed(self, item): idx = self.remotes.row(item) if idx < 0: return if idx >= len(self.remote_list): return old_name = self.remote_list[idx] new_name = unicode(item.text()) if new_name == old_name: return if not new_name: item.setText(old_name) return title = 'Rename Remote' question = 'Rename remote?' info = unicode( self.tr('Rename remote "%s" to "%s"?')) % (old_name, new_name) ok_btn = 'Rename' if qtutils.confirm(title, question, info, ok_btn): git.remote('rename', old_name, new_name) self.remote_list[idx] = new_name else: item.setText(old_name)
def create_branch(self): """Creates a branch; called by the "Create Branch" button""" self.getopts() revision = self.opts.revision branch = self.opts.branch no_update = self.no_update_radio.isChecked() ffwd_only = self.ffwd_only_radio.isChecked() existing_branches = gitcmds.branch_list() check_branch = False if not branch or not revision: qtutils.critical(N_('Missing Data'), N_('Please provide both a branch ' 'name and revision expression.')) return if branch in existing_branches: if no_update: msg = N_('Branch "%s" already exists.') % branch qtutils.critical(N_('Branch Exists'), msg) return # Whether we should prompt the user for lost commits commits = gitcmds.rev_list_range(revision, branch) check_branch = bool(commits) if check_branch: msg = (N_('Resetting "%(branch)s" to "%(revision)s" ' 'will lose commits.') % dict(branch=branch, revision=revision)) if ffwd_only: qtutils.critical(N_('Branch Exists'), msg) return lines = [msg] for idx, commit in enumerate(commits): subject = commit[1][0:min(len(commit[1]),16)] if len(subject) < len(commit[1]): subject += '...' lines.append('\t' + commit[0][:8] +'\t' + subject) if idx >= 5: skip = len(commits) - 5 lines.append('\t(%s)' % (N_('%d skipped') % skip)) break line = N_('Recovering lost commits may not be easy.') lines.append(line) if not qtutils.confirm(N_('Reset Branch?'), '\n'.join(lines), (N_('Reset "%(branch)s" to "%(revision)s"?') % dict(branch=branch, revision=revision)), N_('Reset Branch'), default=False, icon=qtutils.theme_icon('edit-undo.svg')): return self.setEnabled(False) self.progress.setEnabled(True) QtGui.QApplication.setOverrideCursor(Qt.WaitCursor) # Show a nice progress bar self.progress.setLabelText(N_('Updating...')) self.progress.show() self.thread.start()
def _revert_unstaged_edits(self, staged=False): if not self.m.undoable(): return if staged: items_to_undo = self.staged() else: items_to_undo = self.modified() if items_to_undo: if not qtutils.confirm( N_('Revert Unstaged Changes?'), N_('This operation drops unstaged changes.\n' 'These changes cannot be recovered.'), N_('Revert the unstaged changes?'), N_('Revert Unstaged Changes'), default=True, icon=qtutils.icon('undo.svg')): return args = [] if not staged and self.m.amending(): args.append(self.m.head) cmds.do(cmds.Checkout, args + ['--'] + items_to_undo) else: msg = N_('No files selected for checkout from HEAD.') Interaction.log(msg)
def remote_renamed(self, item): idx = self.remotes.row(item) if idx < 0: return if idx >= len(self.remote_list): return old_name = self.remote_list[idx] new_name = unicode(item.text()) if new_name == old_name: return if not new_name: item.setText(old_name) return title = N_("Rename Remote") question = N_("Rename remote?") info = N_('Rename remote "%(current)s" to "%(new)s"?') % dict(current=old_name, new=new_name) ok_btn = N_("Rename") if qtutils.confirm(title, question, info, ok_btn): git.remote("rename", old_name, new_name) self.remote_list[idx] = new_name else: item.setText(old_name)
def remote_renamed(self, item): idx = self.remotes.row(item) if idx < 0: return if idx >= len(self.remote_list): return old_name = self.remote_list[idx] new_name = unicode(item.text()) if new_name == old_name: return if not new_name: item.setText(old_name) return title = N_('Rename Remote') question = N_('Rename remote?') info = (N_('Rename remote "%(current)s" to "%(new)s"?') % dict(current=old_name, new=new_name)) ok_btn = N_('Rename') if qtutils.confirm(title, question, info, ok_btn): status, out, err = git.remote('rename', old_name, new_name) if status == 0: self.remote_list[idx] = new_name else: item.setText(old_name)
def create_tag(self): """Verifies inputs and emits a notifier tag message.""" revision = self.revision.value() tag_name = self.tag_name.value() tag_msg = self.tag_msg.value() sign_tag = self.sign_tag.isChecked() if not revision: critical(N_('Missing Revision'), N_('Please specify a revision to tag.')) return elif not tag_name: critical(N_('Missing Name'), N_('Please specify a name for the new tag.')) return elif (sign_tag and not tag_msg and not qtutils.confirm(N_('Missing Tag Message'), N_('Tag-signing was requested but the tag ' 'message is empty.'), N_('An unsigned, lightweight tag will be ' 'created instead.\n' 'Create an unsigned tag?'), N_('Create Unsigned Tag'), default=False, icon=qtutils.save_icon())): return cmds.do(cmds.Tag, tag_name, revision, sign=sign_tag, message=tag_msg) information(N_('Tag Created'), N_('Created a new tag named "%s"') % tag_name, details=tag_msg or None) self.accept()
def clear(self): if not qtutils.confirm( N_('Clear commit message?'), N_('The commit message will be cleared.'), N_('This cannot be undone. Clear commit message?'), N_('Clear commit message'), default=True, icon=icons.discard()): return self.model.set_commitmsg('')
def clear(self): if not qtutils.confirm( N_("Clear commit message?"), N_("The commit message will be cleared."), N_("This cannot be undone. Clear commit message?"), N_("Clear commit message"), default=True, icon=qtutils.discard_icon(), ): return self.model.set_commitmsg("")
def revert_selection(self): """Destructively check out content for the selected file from $head.""" if not qtutils.confirm(N_('Revert Selected Lines?'), N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), N_('Revert Selected Lines'), default=True, icon=qtutils.icon('undo.svg')): return self.process_diff_selection(staged=False, apply_to_worktree=True, reverse=True, selected=True)
def revert(self): """Signal that we should revert changes to a path.""" if not qtutils.confirm(N_('Revert Uncommitted Changes?'), N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), N_('Revert Uncommitted Changes'), default=True, icon=qtutils.icon('undo.svg')): return paths = self.selected_tracked_paths() cmds.do(cmds.Checkout, ['HEAD', '--'] + paths)
def abort_merge(): """Prompts before aborting a merge in progress """ title = qtutils.tr('Abort Merge...') txt = ('Aborting the current merge will cause ' '*ALL* uncommitted changes to be lost.\n' 'Recovering uncommitted changes is not possible.') info_txt = 'Aborting the current merge?' ok_txt = 'Abort Merge' if qtutils.confirm(title, txt, info_txt, ok_txt, default=False, icon=qtutils.icon('undo.svg')): gitcmds.abort_merge()
def revert(self): """Signal that we should revert changes to a path.""" if not qtutils.confirm('Revert Uncommitted Changes?', 'This operation drops uncommitted changes.' '\nThese changes cannot be recovered.', 'Revert the uncommitted changes?', 'Revert Uncommitted Changes', default=True, icon=qtutils.icon('undo.svg')): return paths = self.selected_tracked_paths() cola.notifier().broadcast(signals.checkout, ['HEAD', '--'] + paths)
def revert_section(self): """Destructively remove a section from a worktree file.""" if not qtutils.confirm(N_('Revert Section?'), N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), N_('Revert Section'), default=True, icon=qtutils.icon('undo.svg')): return self.process_diff_selection(staged=False, apply_to_worktree=True, reverse=True)
def revert_section(self): """Destructively remove a section from a worktree file.""" if not qtutils.confirm(N_('Revert Diff Region?'), N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), N_('Revert Diff Region'), default=True, icon=qtutils.icon('undo.svg')): return self.process_diff_selection(staged=False, apply_to_worktree=True, reverse=True)
def abort_merge(): """Prompts before aborting a merge in progress """ title = N_('Abort Merge...') txt = N_('Aborting the current merge will cause ' '*ALL* uncommitted changes to be lost.\n' 'Recovering uncommitted changes is not possible.') info_txt = N_('Aborting the current merge?') ok_txt = N_('Abort Merge') if qtutils.confirm(title, txt, info_txt, ok_txt, default=False, icon=qtutils.icon('undo.svg')): gitcmds.abort_merge()
def revert(self): """Signal that we should revert changes to a path.""" if not qtutils.confirm('Revert Uncommitted Changes?', 'This operation drops uncommitted changes.' '\nThese changes cannot be recovered.', 'Revert the uncommitted changes?', 'Revert Uncommitted Changes', default=False, icon=qtutils.icon('undo.svg')): return paths = self.selected_tracked_paths() cola.notifier().broadcast(signals.checkout, ['HEAD', '--'] + paths)
def abort_merge(): """Prompts before aborting a merge in progress """ title = N_("Abort Merge...") txt = N_( "Aborting the current merge will cause " "*ALL* uncommitted changes to be lost.\n" "Recovering uncommitted changes is not possible." ) info_txt = N_("Aborting the current merge?") ok_txt = N_("Abort Merge") if qtutils.confirm(title, txt, info_txt, ok_txt, default=False, icon=icons.undo()): gitcmds.abort_merge()
def save_archive(self): filename = self.filename if not filename: return if core.exists(filename): title = N_('Overwrite File?') msg = N_('The file "%s" exists and will be overwritten.') % filename info_txt = N_('Overwrite "%s"?') % filename ok_txt = N_('Overwrite') if not qtutils.confirm(title, msg, info_txt, ok_txt, default=False, icon=icons.save()): return self.accept()
def revert(self): """Signal that we should revert changes to a path.""" if not qtutils.confirm( N_("Revert Uncommitted Changes?"), N_("This operation drops uncommitted changes.\n" "These changes cannot be recovered."), N_("Revert the uncommitted changes?"), N_("Revert Uncommitted Changes"), default=True, icon=qtutils.icon("undo.svg"), ): return paths = self.selected_tracked_paths() cmds.do(cmds.Checkout, ["HEAD", "--"] + paths)
def save_archive(self): filename = self.filename if not filename: return if os.path.exists(filename): title = 'Overwrite File?' msg = 'The file "%s" exists and will be overwritten.' % filename info_txt = 'Overwrite "%s"?' % filename ok_txt = 'Overwrite' icon = qtutils.save_icon() if not qtutils.confirm( title, msg, info_txt, ok_txt, default=False, icon=icon): return self.accept()
def save_archive(self): filename = self.filename if not filename: return if os.path.exists(filename): title = 'Overwrite File?' msg = 'The file "%s" exists and will be overwritten.' % filename info_txt = 'Overwrite "%s"?' % filename ok_txt = 'Overwrite' icon = qtutils.save_icon() if not qtutils.confirm(title, msg, info_txt, ok_txt, default=False, icon=icon): return self.accept()
def commit(self): """Attempt to create a commit from the index and commit message.""" msg = unicode(self.commitmsg.toPlainText()) if not msg: # Describe a good commit message error_msg = self.tr('' 'Please supply a commit message.\n\n' 'A good commit message has the following format:\n\n' '- First line: Describe in one sentence what you did.\n' '- Second line: Blank\n' '- Remaining lines: Describe why this change is good.\n') qtutils.log(1, error_msg) cola.notifier().broadcast(signals.information, 'Missing Commit Message', error_msg) return if not self.model.staged: error_msg = self.tr('' 'No changes to commit.\n\n' 'You must stage at least 1 file before you can commit.') if self.model.modified: informative_text = self.tr('Would you like to stage ' 'and commit all modified files?') if not qtutils.confirm(self, 'Stage and commit?', error_msg, informative_text, ok_text='Stage and Commit'): return else: cola.notifier().broadcast(signals.information, 'Nothing to commit', error_msg) return cola.notifier().broadcast(signals.stage_modified) # Warn that amending published commits is generally bad amend = self.amend_checkbox.isChecked() if (amend and self.model.is_commit_published() and not qtutils.question(self, 'Rewrite Published Commit?', 'This commit has already been published.\n' 'You are rewriting published history.\n' 'You probably don\'t want to do this.\n\n' 'Continue?', default=False)): return # Perform the commit cola.notifier().broadcast(signals.commit, amend, msg)
def save_archive(self): filename = self.filename if not filename: return if core.exists(filename): title = N_('Overwrite File?') msg = N_( 'The file "%s" exists and will be overwritten.') % filename info_txt = N_('Overwrite "%s"?') % filename ok_txt = N_('Overwrite') if not qtutils.confirm( title, msg, info_txt, ok_txt, default=False, icon=icons.save()): return self.accept()
def _revert_uncommitted_edits(self, items_to_undo): if items_to_undo: if not qtutils.confirm( N_('Revert Uncommitted Changes?'), N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), N_('Revert Uncommitted Changes'), default=True, icon=qtutils.icon('undo.svg')): return cmds.do(cmds.Checkout, [self.m.head, '--'] + items_to_undo) else: msg = N_('No files selected for checkout from HEAD.') Interaction.log(msg)
def _revert_uncommitted_edits(self, items_to_undo): if items_to_undo: if not qtutils.confirm( N_("Revert Uncommitted Changes?"), N_("This operation drops uncommitted changes.\n" "These changes cannot be recovered."), N_("Revert the uncommitted changes?"), N_("Revert Uncommitted Changes"), default=True, icon=qtutils.icon("undo.svg"), ): return cmds.do(cmds.Checkout, [self.m.head, "--"] + items_to_undo) else: msg = N_("No files selected for checkout from HEAD.") Interaction.log(msg)
def stash_drop(self): """Drops the currently selected stash """ selection = self.selected_stash() name = self.selected_name() if not selection: return if not qtutils.confirm(N_('Drop Stash?'), N_('Recovering a dropped stash is not possible.'), N_('Drop the "%s" stash?') % name, N_('Drop Stash'), default=True, icon=icons.discard()): return cmds.do(DropStash, selection) self.update_from_model() self.stash_text.setPlainText('')
def _revert_uncommitted_edits(self): items_to_undo = self.modified() if items_to_undo: if not qtutils.confirm('Revert Uncommitted Changes?', 'This operation drops uncommitted changes.' '\nThese changes cannot be recovered.', 'Revert the uncommitted changes?', 'Revert Uncommitted Changes', default=True, icon=qtutils.icon('undo.svg')): return cola.notifier().broadcast(signals.checkout, [self.m.head, '--'] + items_to_undo) else: qtutils.log(1, self.tr('No files selected for ' 'checkout from HEAD.'))
def stash_drop(self): """Drops the currently selected stash """ selection = self.selected_stash() name = self.selected_name() if not selection: return if not qtutils.confirm('Drop Stash?', 'Recovering a dropped stash is not possible.', 'Drop the "%s" stash?' % name, 'Drop Stash', default=True, icon=qtutils.discard_icon()): return self.emit(SIGNAL(drop_stash), selection) self.update_from_model() self.stash_text.setPlainText('')
def revert_selection(self): """Destructively revert selected lines or hunk from a worktree file.""" if self.has_selection(): title = N_('Revert Selected Lines?') ok_text = N_('Revert Selected Lines') else: title = N_('Revert Diff Hunk?') ok_text = N_('Revert Diff Hunk') if not qtutils.confirm(title, N_('This operation drops uncommitted changes.\n' 'These changes cannot be recovered.'), N_('Revert the uncommitted changes?'), ok_text, default=True, icon=icons.undo()): return self.process_diff_selection(reverse=True, apply_to_worktree=True)
def closeEvent(self, event): if self.proc.state() != QtCore.QProcess.NotRunning: # The process is still running, make sure we really want to abort. title = N_('Abort Action') msg = N_('An action is still running.\n' 'Terminating it could result in data loss.') info_text = N_('Abort the action?') ok_text = N_('Abort Action') if qtutils.confirm(title, msg, info_text, ok_text, default=False, icon=qtutils.discard_icon()): self.abortProc() event.accept() else: event.ignore() else: event.accept() return standard.Dialog.closeEvent(self, event)
def delete(self): remote = qtutils.selected_item(self.remotes, self.remote_list) if remote is None: return title = N_('Delete Remote') question = N_('Delete remote?') info = N_('Delete remote "%s"') % remote ok_btn = N_('Delete') if not qtutils.confirm(title, question, info, ok_btn): return status, out, err = git.remote('rm', remote) if status != 0: qtutils.critical( N_('Error deleting remote "%s"') % remote, out + err) main.model().update_status() self.refresh()
def create_tag(self): """Verifies inputs and emits a notifier tag message.""" revision = self.revision.value() tag_name = self.tag_name.value() tag_msg = self.tag_msg.value() sign_tag = self.sign_tag.isChecked() if not revision: qtutils.critical(N_('Missing Revision'), N_('Please specify a revision to tag.')) return elif not tag_name: qtutils.critical(N_('Missing Name'), N_('Please specify a name for the new tag.')) return elif (sign_tag and not tag_msg and not qtutils.confirm(N_('Missing Tag Message'), N_('Tag-signing was requested but the tag ' 'message is empty.'), N_('An unsigned, lightweight tag will be ' 'created instead.\n' 'Create an unsigned tag?'), N_('Create Unsigned Tag'), default=False, icon=icons.save())): return status, output, err = cmds.do(cmds.Tag, tag_name, revision, sign=sign_tag, message=tag_msg) if status == 0: qtutils.information(N_('Tag Created'), N_('Created a new tag named "%s"') % tag_name, details=tag_msg or None) self.close() else: qtutils.critical( N_('Error: could not create tag "%s"') % tag_name, (N_('git tag returned exit code %s') % status) + ((output + err) and ('\n\n' + output + err) or ''))
def delete(self): remote = qtutils.selected_item(self.remotes, self.remote_list) if remote is None: return title = 'Delete Remote' question = 'Delete remote?' info = unicode(self.tr('Delete remote "%s"')) % remote ok_btn = 'Delete' if not qtutils.confirm(title, question, info, ok_btn): return status, out = git.remote('rm', remote, with_status=True, with_stderr=True) if status != 0: qtutils.critical('Error deleting remote "%s"' % remote, out) cola.model().update_status() self.refresh()
def _delete_files(self): files = self.untracked() count = len(files) if count == 0: return title = 'Delete Files?' msg = self.tr('The following files will be deleted:\n\n') fileinfo = subprocess.list2cmdline(files) if len(fileinfo) > 2048: fileinfo = fileinfo[:2048].rstrip() + '...' msg += fileinfo info_txt = unicode(self.tr('Delete %d file(s)?')) % count ok_txt = 'Delete Files' if qtutils.confirm(title, msg, info_txt, ok_txt, default=True, icon=qtutils.discard_icon()): cola.notifier().broadcast(signals.delete, files)
def _delete_files(self): files = self.untracked() count = len(files) if count == 0: return title = N_('Delete Files?') msg = N_('The following files will be deleted:') + '\n\n' fileinfo = subprocess.list2cmdline(files) if len(fileinfo) > 2048: fileinfo = fileinfo[:2048].rstrip() + '...' msg += fileinfo info_txt = N_('Delete %d file(s)?') % count ok_txt = N_('Delete Files') if qtutils.confirm(title, msg, info_txt, ok_txt, default=True, icon=qtutils.discard_icon()): cmds.do(cmds.Delete, files)
def _revert_unstaged_edits(self, staged=False): if not self.m.undoable(): return if staged: items_to_undo = self.staged() else: items_to_undo = self.modified() if items_to_undo: if not qtutils.confirm(N_('Revert Unstaged Changes?'), N_('This operation drops unstaged changes.\n' 'These changes cannot be recovered.'), N_('Revert the unstaged changes?'), N_('Revert Unstaged Changes'), default=True, icon=qtutils.icon('undo.svg')): return args = [] if not staged and self.m.amending(): args.append(self.m.head) cmds.do(cmds.Checkout, args + ['--'] + items_to_undo) else: msg = N_('No files selected for checkout from HEAD.') Interaction.log(msg)
def action_callback(self): action = self.action if action == FETCH: model_action = self.model.fetch elif action == PUSH: model_action = self.model.push else: # if action == PULL: model_action = self.model.pull remote_name = unicode(self.remote_name.text()) if not remote_name: errmsg = self.tr('No repository selected.') qtutils.log(1, errmsg) return remote, kwargs = self.common_args() # Check if we're about to create a new branch and warn. remote_branch = unicode(self.remote_branch.text()) local_branch = unicode(self.local_branch.text()) if action == PUSH and not remote_branch: branch = local_branch candidate = '%s/%s' % (remote, branch) if candidate not in self.model.remote_branches: title = self.tr(PUSH) msg = 'Branch "%s" does not exist in %s.' % (branch, remote) msg += '\nA new remote branch will be published.' info_txt = 'Create a new remote branch?' ok_text = 'Create Remote Branch' if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=qtutils.git_icon()): return if not self.ffwd_only_checkbox.isChecked(): title = 'Force %s?' % action.title() ok_text = 'Force %s' % action.title() if action == FETCH: msg = 'Non-fast-forward fetch overwrites local history!' info_txt = 'Force fetching from %s?' % remote elif action == PUSH: msg = ('Non-fast-forward push overwrites published ' 'history!\n(Did you pull first?)') info_txt = 'Force push to %s?' % remote else: # pull: shouldn't happen since the controls are hidden msg = "You probably don't want to do this.\n\tContinue?" return if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=qtutils.discard_icon()): return # Disable the GUI by default self.setEnabled(False) self.progress.setEnabled(True) QtGui.QApplication.setOverrideCursor(Qt.WaitCursor) # Show a nice progress bar self.progress_thread.start() self.progress.show() # Use a thread to update in the background task = ActionTask(self, model_action, remote, kwargs) self.tasks.append(task) QtCore.QThreadPool.globalInstance().start(task)
def action_callback(self): action = self.action if action == FETCH: model_action = self.model.fetch elif action == PUSH: model_action = self.push_to_all else: # if action == PULL: model_action = self.model.pull remote_name = ustr(self.remote_name.text()) if not remote_name: errmsg = N_('No repository selected.') Interaction.log(errmsg) return remote, kwargs = self.common_args() self.selected_remotes = qtutils.selected_items(self.remotes, self.model.remotes) # Check if we're about to create a new branch and warn. remote_branch = ustr(self.remote_branch.text()) local_branch = ustr(self.local_branch.text()) if action == PUSH and not remote_branch: branch = local_branch candidate = '%s/%s' % (remote, branch) if candidate not in self.model.remote_branches: title = N_('Push') args = dict(branch=branch, remote=remote) msg = N_( 'Branch "%(branch)s" does not exist in "%(remote)s".\n' 'A new remote branch will be published.') % args info_txt = N_('Create a new remote branch?') ok_text = N_('Create Remote Branch') if not qtutils.confirm( title, msg, info_txt, ok_text, icon=qtutils.git_icon()): return if not self.ffwd_only_checkbox.isChecked(): if action == FETCH: title = N_('Force Fetch?') msg = N_('Non-fast-forward fetch overwrites local history!') info_txt = N_('Force fetching from %s?') % remote ok_text = N_('Force Fetch') elif action == PUSH: title = N_('Force Push?') msg = N_('Non-fast-forward push overwrites published ' 'history!\n(Did you pull first?)') info_txt = N_('Force push to %s?') % remote ok_text = N_('Force Push') else: # pull: shouldn't happen since the controls are hidden msg = "You probably don't want to do this.\n\tContinue?" return if not qtutils.confirm(title, msg, info_txt, ok_text, default=False, icon=qtutils.discard_icon()): return # Disable the GUI by default self.action_button.setEnabled(False) self.close_button.setEnabled(False) # Use a thread to update in the background task = ActionTask(self.task_runner, model_action, remote, kwargs) self.task_runner.start(task, progress=self.progress, finish=self.action_completed)