sub checkout_minimal()

in lib/ES/TargetRepo.pm [42:85]


sub checkout_minimal {
#===================================
    my ( $self ) = @_;

    # Whether or not we'll need to force push the target branch.
    $self->{rebuilding_target_branch} = 0;

    my $original_pwd = Cwd::cwd();
    eval {
        my $out = run qw(git clone --no-checkout),
            $self->git_dir, $self->{destination};

        # This if statement handles empty repositories in a way that works with
        # different target branches. It always checks out the master
        # branch. If the target branch is `master` then it will return early.
        # If the target branch isn't master it'll delete the existing copy
        # of the branch.
        if ( $out =~ /You appear to have cloned an empty repository./) {
            $self->{started_empty} = 1;
            printf(" - %20s: Initializing empty master for empty repo\n",
                'target_repo');
            return 1 if $self->{branch} eq 'master';
            chdir $self->{destination};
            $self->{initialized_empty_master} = 1;
            run qw(git commit --allow-empty -m init);
        } else {
            $self->{started_empty} = 0;
            chdir $self->{destination};
            run qw(git config core.sparseCheckout true);
            $self->_write_sparse_config( $self->{destination}, "/*\n!html/*/\n!raw/*/" );
            run qw(git checkout master);
            return 1 if $self->{branch} eq 'master';
            if ( $self->_branch_exists( 'origin/' . $self->{branch} ) ) {
                $self->{rebuilding_target_branch} = 1;
            }
        }

        printf(" - %20s: Forking <%s> from master\n",
            'target_repo', $self->{branch});
        run qw(git checkout -b), $self->{branch};
        1;
    } or die "Error checking out repo <target_repo>: $@";
    chdir $original_pwd;
}