Exemplo n.º 1
0
 def add_bookmark(self):
     path, ok = qtutils.prompt(N_('Path to git repository'),
                               title=N_('Enter Git Repository'),
                               text=core.getcwd())
     if not ok:
         return
     normpath = utils.expandpath(path)
     if git.is_git_worktree(normpath):
         self.settings.add_bookmark(normpath)
         self.settings.save()
         self.refresh()
     else:
         qtutils.critical(N_('Error'),
                          N_('%s is not a Git repository.') % path)
Exemplo n.º 2
0
 def add_bookmark(self):
     path, ok = qtutils.prompt(N_('Path to git repository'),
                               title=N_('Enter Git Repository'),
                               text=core.getcwd())
     if not ok:
         return
     normpath = utils.expandpath(path)
     if git.is_git_worktree(normpath):
         self.settings.add_bookmark(normpath)
         self.settings.save()
         self.refresh()
     else:
         qtutils.critical(N_('Error'),
                          N_('%s is not a Git repository.') % path)
Exemplo n.º 3
0
def new_repo():
    """Prompt for a new directory and create a new Git repository

    :returns str: repository path or None if no repository was created.

    """
    dlg = QtGui.QFileDialog()
    dlg.setFileMode(QtGui.QFileDialog.Directory)
    dlg.setOption(QtGui.QFileDialog.ShowDirsOnly)
    dlg.show()
    dlg.raise_()
    if dlg.exec_() != QtGui.QFileDialog.Accepted:
        return None
    paths = dlg.selectedFiles()
    if not paths:
        return None
    path = paths[0]
    if not path:
        return None
    # Avoid needlessly calling `git init`.
    if git.is_git_worktree(path) or git.is_git_dir(path):
        # We could prompt here and confirm that they really didn't
        # mean to open an existing repository, but I think
        # treating it like an "Open" is a sensible DWIM answer.
        return path

    status, out, err = core.run_command(['git', 'init', path])
    if status == 0:
        return path
    else:
        title = N_('Error Creating Repository')
        msg = (N_('"%(command)s" returned exit status %(status)d') %
               dict(command='git init %s' % path, status=status))
        details = N_('Output:\n%s') % out
        if err:
            details += '\n\n'
            details += N_('Errors: %s') % err
        qtutils.critical(title, msg, details)
        return None
Exemplo n.º 4
0
def new_repo():
    """Prompt for a new directory and create a new Git repository

    :returns str: repository path or None if no repository was created.

    """
    dlg = QtGui.QFileDialog()
    dlg.setFileMode(QtGui.QFileDialog.Directory)
    dlg.setOption(QtGui.QFileDialog.ShowDirsOnly)
    dlg.show()
    dlg.raise_()
    if dlg.exec_() != QtGui.QFileDialog.Accepted:
        return None
    paths = dlg.selectedFiles()
    if not paths:
        return None
    path = paths[0]
    if not path:
        return None
    # Avoid needlessly calling `git init`.
    if git.is_git_worktree(path) or git.is_git_dir(path):
        # We could prompt here and confirm that they really didn't
        # mean to open an existing repository, but I think
        # treating it like an "Open" is a sensible DWIM answer.
        return path

    status, out, err = core.run_command(['git', 'init', path])
    if status == 0:
        return path
    else:
        title = N_('Error Creating Repository')
        msg = (N_('"%(command)s" returned exit status %(status)d') %
               dict(command='git init %s' % path, status=status))
        details = N_('Output:\n%s') % out
        if err:
            details += '\n\n'
            details += N_('Errors: %s') % err
        qtutils.critical(title, msg, details)
        return None