#!/bin/bash
# Copyright 2020 gRPC authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

cd /src/workspace
ls -A | xargs -r rm -fr
git clone --recursive $CLONE_REPO .
git checkout $CLONE_GIT_REF

#!/bin/bash
# Copyright 2020 gRPC authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex
cd /src/workspace
ls -A | xargs -r rm -fr
git init
git remote add origin $CLONE_REPO
git fetch
git reset --hard $CLONE_GIT_REF
git submodule update --init --recursive
chmod -R 777 .

Remove unnecessary checkouts when cloning
Remove unnecessary checkouts when cloning

The clone docker image is used as an init container which fetches the
code at a specific commit, tag or branch. Previously, it used the
git-clone command, which clones the master branch by default. Developers
wanted to avoid the unnecessary checkout when they are testing off
another branch or tag.

The git-clone command does provide the --branch and --single-branch
flags, but these options are incompatible with commits due to a
server-side setting that GitHub has not enabled.

This commit achieves similar behavior, but it uses an empty git
repository, fetches a remote and resets to a specific branch, tag or
commit. This avoids the unnecessary checkout.
