示例#1
0
def main(argv):
    retval = 0

    (options, args) = parse_args(argv)
    if not options:
        return 1

    if len(args) < 2:
        gbp.log.err("Need a repository to clone.")
        return 1
    else:
        source = args[1]

    clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False)
    try:
        GitRepository(clone_to)
        gbp.log.err("Can't run inside a git repository.")
        return 1
    except GitRepositoryError:
        pass

    try:
        repo = DebianGitRepository.clone(clone_to, source, options.depth,
                                         auto_name=auto_name)
        os.chdir(repo.path)

        # Reparse the config files of the cloned repository so we pick up the
        # branch information from there:
        (options, args) = parse_args(argv)

        # Track all branches:
        if options.all:
            remotes = repo.get_remote_branches()
            for remote in remotes:
                local = remote.replace("origin/", "", 1)
                if not repo.has_branch(local) and \
                    local != "HEAD":
                        repo.create_branch(local, remote)
        else: # only track gbp's default branches
            branches = [ options.debian_branch, options.upstream_branch ]
            if options.pristine_tar:
                branches += [ repo.pristine_tar_branch ]
            gbp.log.debug('Will track branches: %s' % branches)
            for branch in branches:
                remote = 'origin/%s' % branch
                if repo.has_branch(remote, remote=True) and \
                    not repo.has_branch(branch):
                        repo.create_branch(branch, remote)

        repo.set_branch(options.debian_branch)

    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError as err:
        if len(err.__str__()):
            gbp.log.err(err)
        retval = 1

    return retval
示例#2
0
def main(argv):
    retval = 0

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) < 2:
        gbp.log.err("Need a repository to clone.")
        return 1
    else:
        source = args[1]

    clone_to, auto_name = (os.path.curdir,
                           True) if len(args) < 3 else (args[2], False)
    try:
        GitRepository(clone_to)
        gbp.log.err("Can't run inside a git repository.")
        return 1
    except GitRepositoryError:
        pass

    try:
        gbp.log.info(
            "Cloning from '%s'%s" %
            (source, " into '%s'" % clone_to if not auto_name else ''))
        repo = DebianGitRepository.clone(clone_to,
                                         source,
                                         options.depth,
                                         auto_name=auto_name,
                                         reference=options.reference)
        os.chdir(repo.path)

        # Reparse the config files of the cloned repository so we pick up the
        # branch information from there but don't overwrite hooks:
        postclone = options.postclone
        (options, args) = parse_args(argv)

        # Track all branches:
        if options.all:
            remotes = repo.get_remote_branches()
            for remote in remotes:
                local = remote.replace("origin/", "", 1)
                if (not repo.has_branch(local) and local != "HEAD"):
                    repo.create_branch(local, remote)
        else:  # only track gbp's default branches
            branches = [options.debian_branch, options.upstream_branch]
            if options.pristine_tar:
                branches += [repo.pristine_tar_branch]
            gbp.log.debug('Will track branches: %s' % branches)
            for branch in branches:
                remote = 'origin/%s' % branch
                if (repo.has_branch(remote, remote=True)
                        and not repo.has_branch(branch)):
                    repo.create_branch(branch, remote)

        repo.set_branch(options.debian_branch)

        repo_setup.set_user_name_and_email(options.repo_user,
                                           options.repo_email, repo)

        if postclone:
            Hook(
                'Postclone',
                options.postclone,
                extra_env={'GBP_GIT_DIR': repo.git_dir},
            )()

    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        retval = 1

    return retval
示例#3
0
def main(argv):
    retval = 0

    (options, args) = parse_args(argv)
    if not options:
        return ExitCodes.parse_error

    if len(args) < 2:
        gbp.log.err("Need a repository to clone.")
        return 1
    else:
        source = repo_to_url(args[1])
        if not source:
            return 1

    clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False)
    try:
        GitRepository(clone_to)
        gbp.log.err("Can't run inside a git repository.")
        return 1
    except GitRepositoryError:
        pass

    try:
        gbp.log.info("Cloning from '%s'%s" % (source, " into '%s'" % clone_to if not auto_name else ''))
        repo = DebianGitRepository.clone(clone_to, source, options.depth,
                                         auto_name=auto_name, reference=options.reference)
        os.chdir(repo.path)

        # Reparse the config files of the cloned repository so we pick up the
        # branch information from there but don't overwrite hooks:
        postclone = options.postclone
        (options, args) = parse_args(argv)

        # Track all branches:
        if options.all:
            remotes = repo.get_remote_branches()
            for remote in remotes:
                local = remote.replace("origin/", "", 1)
                if (not repo.has_branch(local) and
                        local != "HEAD"):
                    repo.create_branch(local, remote)
        else:  # only track gbp's default branches
            branches = [options.debian_branch, options.upstream_branch]
            if options.pristine_tar:
                branches += [repo.pristine_tar_branch]
            gbp.log.debug('Will track branches: %s' % branches)
            for branch in branches:
                remote = 'origin/%s' % branch
                if (repo.has_branch(remote, remote=True) and
                        not repo.has_branch(branch)):
                    repo.create_branch(branch, remote)

        repo.set_branch(options.debian_branch)

        repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)

        if postclone:
            Hook('Postclone', options.postclone,
                 extra_env={'GBP_GIT_DIR': repo.git_dir},
                 )()

    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        retval = 1

    return retval