Skip to content

Commit 62a382c

Browse files
Merge pull request #181 from tiborvass/fix-version
Add checkout.sh to handle tags with shallow clones
2 parents 12e42d5 + fbe9af0 commit 62a382c

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ docker.io/%:
6868

6969
.PHONY: checkout
7070
checkout: src
71-
@git -C src/github.com/opencontainers/runc fetch --depth 1 origin "$(RUNC_REF)"
72-
@git -C src/github.com/opencontainers/runc checkout -q FETCH_HEAD
73-
@git -C src/github.com/containerd/containerd fetch --depth 1 origin "$(REF)"
74-
@git -C src/github.com/containerd/containerd checkout -q FETCH_HEAD
71+
./scripts/checkout.sh src/github.com/opencontainers/runc "$(RUNC_REF)"
72+
./scripts/checkout.sh src/github.com/containerd/containerd "$(REF)"
7573

7674
.PHONY: build
7775
build: checkout

scripts/checkout.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env sh
2+
3+
# Copyright 2018-2020 Docker Inc.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
checkout() (
18+
set -ex
19+
SRC="$1"
20+
REF="$2"
21+
REF_FETCH="$REF"
22+
# if ref is branch or tag, retrieve its canonical form
23+
REF=$(git -C "$SRC" ls-remote --refs --heads --tags origin "$REF" | awk '{print $2}')
24+
if [ -n "$REF" ]; then
25+
# if branch or tag then create it locally too
26+
REF_FETCH="$REF:$REF"
27+
else
28+
REF="FETCH_HEAD"
29+
fi
30+
git -C "$SRC" fetch --depth 1 origin "$REF_FETCH"
31+
git -C "$SRC" checkout -q "$REF"
32+
)
33+
34+
35+
# Only execute checkout function above if this file is executed, not sourced from another script
36+
prog=checkout.sh # needs to be in sync with this file's name
37+
if [ "$(basename -- $0)" = "$prog" ]; then
38+
checkout $*
39+
fi

0 commit comments

Comments
 (0)