Exemple #1
0
    def test_is_git_dir_finds_linked_repository(self, isfile, isdir, islink):
        dirs = set(
            [
                '/foo',
                '/foo/.git',
                '/foo/.git/refs',
                '/foo/.git/objects',
                '/foo/.git/worktrees',
                '/foo/.git/worktrees/foo',
            ]
        )
        files = set(
            [
                '/foo/.git/HEAD',
                '/foo/.git/worktrees/foo/HEAD',
                '/foo/.git/worktrees/foo/index',
                '/foo/.git/worktrees/foo/commondir',
                '/foo/.git/worktrees/foo/gitdir',
            ]
        )
        islink.return_value = False
        isfile.side_effect = lambda x: x in files
        isdir.side_effect = lambda x: x in dirs

        self.assertTrue(git.is_git_dir('/foo/.git/worktrees/foo'))
        self.assertTrue(git.is_git_dir('/foo/.git'))
Exemple #2
0
    def _new(self):
        dlg = QtGui.QFileDialog(self)
        dlg.setFileMode(QtGui.QFileDialog.Directory)
        dlg.setOption(QtGui.QFileDialog.ShowDirsOnly)
        if dlg.exec_() != QtGui.QFileDialog.Accepted:
            return
        paths = dlg.selectedFiles()
        if not paths:
            return
        upath = unicode(paths[0])
        if not upath:
            return
        path = core.encode(unicode(paths[0]))
        # Avoid needlessly calling `git init`.
        if 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.
            self._gitdir = upath
            self.accept()
            return

        os.chdir(path)
        status, out, err = utils.run_command(['git', 'init'])
        if status != 0:
            title = 'Error Creating Repository'
            msg = 'git init returned exit status %d' % status
            details = 'output:\n%s\n\nerrors:\n%s' % (out, err)
            qtutils.critical(title, msg, details)
        else:
            self._gitdir = upath
            self.accept()
Exemple #3
0
    def _new(self):
        dlg = QtGui.QFileDialog(self)
        dlg.setFileMode(QtGui.QFileDialog.Directory)
        dlg.setOption(QtGui.QFileDialog.ShowDirsOnly)
        if dlg.exec_() != QtGui.QFileDialog.Accepted:
            return
        paths = dlg.selectedFiles()
        if not paths:
            return
        upath = unicode(paths[0])
        if not upath:
            return
        path = core.encode(unicode(paths[0]))
        # Avoid needlessly calling `git init`.
        if 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.
            self._gitdir = upath
            self.accept()
            return

        os.chdir(path)
        status, out, err = utils.run_command(['git', 'init'])
        if status != 0:
            title = 'Error Creating Repository'
            msg = 'git init returned exit status %d' % status
            details = 'output:\n%s\n\nerrors:\n%s' % (out, err)
            qtutils.critical(title, msg, details)
        else:
            self._gitdir = upath
            self.accept()
Exemple #4
0
    def test_is_git_dir_finds_linked_repository(self, isfile, isdir, islink):
        dirs = set([
            '/foo',
            '/foo/.git',
            '/foo/.git/refs',
            '/foo/.git/objects',
            '/foo/.git/worktrees',
            '/foo/.git/worktrees/foo',
        ])
        files = set([
            '/foo/.git/HEAD',
            '/foo/.git/worktrees/foo/HEAD',
            '/foo/.git/worktrees/foo/index',
            '/foo/.git/worktrees/foo/commondir',
            '/foo/.git/worktrees/foo/gitdir',
        ])
        islink.return_value = False
        isfile.side_effect = lambda x: x in files
        isdir.side_effect = lambda x: x in dirs

        self.assertTrue(git.is_git_dir('/foo/.git/worktrees/foo'))
        self.assertTrue(git.is_git_dir('/foo/.git'))
Exemple #5
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
Exemple #6
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