diff --git a/.gitignore b/.gitignore index 5e56e04..f0c128e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /bin +/.go +/.push-* +/.container-* +/.dockerfile-* diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index aa090dd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM gcr.io/google_containers/ubuntu-slim:0.1 - -ARG ARCH -ADD bin/git-sync-${ARCH} /git-sync - -ENV GIT_SYNC_DEST /git - -RUN apt-get update && \ - apt-get install -y git ca-certificates --no-install-recommends && \ - apt-get install -y openssh-client && \ - apt-get clean -y && \ - rm -rf /var/lib/apt/lists/* - -# Move the existing SSH binary, then replace it with the wrapper script -RUN mv /usr/bin/ssh /usr/bin/ssh-binary -COPY ssh-wrapper.sh /usr/bin/ssh -RUN chmod 755 /usr/bin/ssh - -RUN mkdir /nonexistent && chmod 777 /nonexistent - -ENTRYPOINT ["/git-sync"] diff --git a/Dockerfile.in b/Dockerfile.in new file mode 100644 index 0000000..5a26983 --- /dev/null +++ b/Dockerfile.in @@ -0,0 +1,33 @@ +# Copyright 2016 The Kubernetes 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 +# +# http://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. + +FROM ARG_FROM + +MAINTAINER Tim Hockin + +ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN +ENV GIT_SYNC_DEST /git + +# Move the existing SSH binary, then replace it with the wrapper script +RUN apk update --no-cache && apk add \ + ca-certificates \ + coreutils \ + git \ + openssh-client +RUN mv /usr/bin/ssh /usr/bin/ssh-binary +ADD ssh-wrapper.sh /usr/bin/ssh +RUN chmod 755 /usr/bin/ssh + +USER nobody:nobody +ENTRYPOINT ["/ARG_BIN"] diff --git a/Makefile b/Makefile index 2c83301..4d4feaf 100644 --- a/Makefile +++ b/Makefile @@ -12,82 +12,150 @@ # See the License for the specific language governing permissions and # limitations under the License. -.PHONY: all push push-legacy container clean +# The binary to build (just the basename). +BIN := git-sync -REGISTRY ?= gcr.io/google_containers -IMAGE = $(REGISTRY)/git-sync-$(ARCH) -LEGACY_AMD64_IMAGE = $(REGISTRY)/git-sync +# This repo's root import path (under GOPATH). +PKG := k8s.io/git-sync -TAG = v2.0.2 +# Where to push the docker image. +REGISTRY ?= gcr.io/google-containers -# Architectures supported: amd64, arm, arm64 and ppc64le +# Which architecture to build - see $(ALL_ARCH) for options. ARCH ?= amd64 -# TODO: get a base image for non-x86 archs -# arm arm64 ppc64le -ALL_ARCH = amd64 +# This version-strategy uses git tags to set the version string +VERSION := $(shell git describe --tags --always --dirty) +# +# This version-strategy uses a manual value to set the version string +#VERSION := 1.2.3 -KUBE_CROSS_IMAGE ?= gcr.io/google_containers/kube-cross -KUBE_CROSS_VERSION ?= v1.6.3-2 +### +### These variables should not need tweaking. +### -GO_PKG = k8s.io/git-sync -BIN = git-sync +SRC_DIRS := cmd pkg # directories which hold app source (not vendored) +ALL_ARCH := amd64 + +# TODO: get a baseimage that works for other architectures +# arm arm64 ppc64le + +# Set default base image dynamically for each arch +ifeq ($(ARCH),amd64) + BASEIMAGE?=alpine:3.4 +endif +ifeq ($(ARCH),arm) + BASEIMAGE?=armel/busybox +endif +ifeq ($(ARCH),arm64) + BASEIMAGE?=aarch64/busybox +endif +ifeq ($(ARCH),ppc64le) + BASEIMAGE?=ppc64le/busybox +endif + +IMAGE := $(REGISTRY)/$(BIN)-$(ARCH) +LEGACY_IMAGE := $(REGISTRY)/$(BIN) + +BUILD_IMAGE ?= golang:1.7-alpine + +# If you want to build all binaries, see the 'all-build' rule. # If you want to build all containers, see the 'all-container' rule. # If you want to build AND push all containers, see the 'all-push' rule. -all: all-build +all: build -sub-container-%: - $(MAKE) ARCH=$* container +build-%: + @$(MAKE) --no-print-directory ARCH=$* build -sub-push-%: - $(MAKE) ARCH=$* push +container-%: + @$(MAKE) --no-print-directory ARCH=$* container -all-build: $(addprefix bin/$(BIN)-,$(ALL_ARCH)) +push-%: + @$(MAKE) --no-print-directory ARCH=$* push -all-container: $(addprefix sub-container-,$(ALL_ARCH)) +all-build: $(addprefix build-, $(ALL_ARCH)) -all-push: $(addprefix sub-push-,$(ALL_ARCH)) +all-container: $(addprefix container-, $(ALL_ARCH)) -build: bin/$(BIN)-$(ARCH) +all-push: $(addprefix push-, $(ALL_ARCH)) -bin/$(BIN)-$(ARCH): FORCE - mkdir -p bin - docker run \ - -u $$(id -u):$$(id -g) \ - -v $$(pwd):/go/src/$(GO_PKG) \ - $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \ - /bin/bash -c " \ - cd /go/src/$(GO_PKG) && \ - CGO_ENABLED=0 go build \ - -installsuffix cgo \ - -ldflags '-w' \ - -o $@" +build: bin/$(ARCH)/$(BIN) -container: .container-$(ARCH) -.container-$(ARCH): bin/$(BIN)-$(ARCH) - docker build -t $(IMAGE):$(TAG) --build-arg ARCH=$(ARCH) . -ifeq ($(ARCH),amd64) - docker tag $(IMAGE):$(TAG) $(LEGACY_AMD64_IMAGE):$(TAG) -endif - touch $@ +bin/$(ARCH)/$(BIN): build-dirs + @echo "building: $@" + @docker run \ + -ti \ + -u $$(id -u):$$(id -g) \ + -v $$(pwd)/.go:/go \ + -v $$(pwd):/go/src/$(PKG) \ + -v $$(pwd)/bin/$(ARCH):/go/bin \ + -v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \ + -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ + -w /go/src/$(PKG) \ + $(BUILD_IMAGE) \ + /bin/sh -c " \ + ARCH=$(ARCH) \ + VERSION=$(VERSION) \ + PKG=$(PKG) \ + ./build/build.sh \ + " -push: .push-$(ARCH) -.push-$(ARCH): .container-$(ARCH) - gcloud docker push $(IMAGE):$(TAG) - touch $@ +DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION) -push-legacy: .push-legacy-$(ARCH) -.push-legacy-$(ARCH): .container-$(ARCH) -ifeq ($(ARCH),amd64) - gcloud docker push $(LEGACY_AMD64_IMAGE):$(TAG) -endif - touch $@ +container: .container-$(DOTFILE_IMAGE) container-name +.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in + @sed \ + -e 's|ARG_BIN|$(BIN)|g' \ + -e 's|ARG_ARCH|$(ARCH)|g' \ + -e 's|ARG_FROM|$(BASEIMAGE)|g' \ + Dockerfile.in > .dockerfile-$(ARCH) + @docker build -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) . + @docker images -q $(IMAGE):$(VERSION) > $@ + @if [ "$(ARCH)" == "amd64" ]; then \ + docker tag $(IMAGE):$(VERSION) $(LEGACY_IMAGE):$(VERSION); \ + fi -test: - @./test.sh +container-name: + @echo "container: $(IMAGE):$(VERSION)" -clean: - rm -rf .container-* .push-* bin/ +push: .push-$(DOTFILE_IMAGE) push-name +.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE) + @gcloud docker push $(IMAGE):$(VERSION) + @docker images -q $(IMAGE):$(VERSION) > $@ + @if [ "$(ARCH)" == "amd64" ]; then \ + gcloud docker push $(LEGACY_IMAGE):$(TAG); \ + fi -FORCE: +push-name: + @echo "pushed: $(IMAGE):$(VERSION)" + +version: + @echo $(VERSION) + +test: build-dirs + @docker run \ + -ti \ + -u $$(id -u):$$(id -g) \ + -v $$(pwd)/.go:/go \ + -v $$(pwd):/go/src/$(PKG) \ + -v $$(pwd)/bin/$(ARCH):/go/bin \ + -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ + -w /go/src/$(PKG) \ + $(BUILD_IMAGE) \ + /bin/sh -c " \ + ./build/test.sh $(SRC_DIRS) \ + " + @./test_e2e.sh + +build-dirs: + @mkdir -p bin/$(ARCH) + @mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH) + +clean: container-clean bin-clean + +container-clean: + rm -rf .container-* .dockerfile-* .push-* + +bin-clean: + rm -rf .go bin diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..ae91479 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# +# Copyright 2016 The Kubernetes 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 +# +# http://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 -o errexit +set -o nounset +set -o pipefail + +if [ -z "${PKG}" ]; then + echo "PKG must be set" + exit 1 +fi +if [ -z "${ARCH}" ]; then + echo "ARCH must be set" + exit 1 +fi +if [ -z "${VERSION}" ]; then + echo "VERSION must be set" + exit 1 +fi + +export CGO_ENABLED=0 +export GOARCH="${ARCH}" + +go install \ + -installsuffix "static" \ + -ldflags "-X ${PKG}/pkg/version.VERSION=${VERSION}" \ + ./... diff --git a/build/test.sh b/build/test.sh new file mode 100755 index 0000000..23b5679 --- /dev/null +++ b/build/test.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# +# Copyright 2016 The Kubernetes 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 +# +# http://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 -o errexit +set -o nounset +set -o pipefail + +export CGO_ENABLED=0 + +TARGETS=$(for d in "$@"; do echo ./$d/...; done) + +echo "Running tests:" +go test -i -installsuffix "static" ${TARGETS} +go test -installsuffix "static" ${TARGETS} +echo + +echo -n "Checking gofmt: " +ERRS=$(find "$@" -type f -name \*.go | xargs gofmt -l 2>&1 || true) +if [ -n "${ERRS}" ]; then + echo "FAIL - the following files need to be gofmt'ed:" + for e in ${ERRS}; do + echo " $e" + done + echo + exit 1 +fi +echo "PASS" +echo + +echo -n "Checking go vet: " +ERRS=$(go vet ${TARGETS} 2>&1 || true) +if [ -n "${ERRS}" ]; then + echo "FAIL" + echo "${ERRS}" + echo + exit 1 +fi +echo "PASS" +echo diff --git a/main.go b/cmd/git-sync/main.go similarity index 94% rename from main.go rename to cmd/git-sync/main.go index 1340e36..4e90cb3 100644 --- a/main.go +++ b/cmd/git-sync/main.go @@ -16,7 +16,7 @@ limitations under the License. // git-sync is a command that pull a git repository to a local directory. -package main // import "k8s.io/git-sync" +package main // import "k8s.io/git-sync/cmd/git-sync" import ( "bytes" @@ -50,7 +50,7 @@ var flRoot = flag.String("root", envString("GIT_SYNC_ROOT", "/git"), "the root directory for git operations") var flDest = flag.String("dest", envString("GIT_SYNC_DEST", ""), "the name at which to publish the checked-out files under --root (defaults to leaf dir of --root)") -var flWait = flag.Int("wait", envInt("GIT_SYNC_WAIT", 0), +var flWait = flag.Float64("wait", envFloat("GIT_SYNC_WAIT", 0), "the number of seconds between syncs") var flOneTime = flag.Bool("one-time", envBool("GIT_SYNC_ONE_TIME", false), "exit after the initial checkout") @@ -101,7 +101,19 @@ func envInt(key string, def int) int { if env := os.Getenv(key); env != "" { val, err := strconv.Atoi(env) if err != nil { - log.Errorf("invalid value for %q: using default: %q", key, def) + log.Errorf("invalid value for %q: using default: %v", key, def) + return def + } + return val + } + return def +} + +func envFloat(key string, def float64) float64 { + if env := os.Getenv(key); env != "" { + val, err := strconv.ParseFloat(env, 64) + if err != nil { + log.Errorf("invalid value for %q: using default: %v", key, def) return def } return val @@ -147,6 +159,7 @@ func main() { } // From here on, output goes through logging. + log.V(0).Infof("starting up: %q", os.Args) initialSync := true failCount := 0 @@ -159,8 +172,8 @@ func main() { failCount++ log.Errorf("unexpected error syncing repo: %v", err) - log.V(0).Infof("waiting %d seconds before retryng", *flWait) - time.Sleep(time.Duration(*flWait) * time.Second) + log.V(0).Infof("waiting %v before retrying", waitTime(*flWait)) + time.Sleep(waitTime(*flWait)) continue } if initialSync { @@ -178,11 +191,15 @@ func main() { } failCount = 0 - log.V(1).Infof("next sync in %d seconds", *flWait) - time.Sleep(time.Duration(*flWait) * time.Second) + log.V(1).Infof("next sync in %v", waitTime(*flWait)) + time.Sleep(waitTime(*flWait)) } } +func waitTime(seconds float64) time.Duration { + return time.Duration(int(seconds*1000)) * time.Millisecond +} + func setFlagDefaults() { // Force logging to stderr. stderrFlag := flag.Lookup("logtostderr") diff --git a/main_test.go b/cmd/git-sync/main_test.go similarity index 100% rename from main_test.go rename to cmd/git-sync/main_test.go diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 0000000..33adb59 --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,19 @@ +/* +Copyright 2016 The Kubernetes 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 + + http://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. +*/ + +package version + +var VERSION = "UNKNOWN" diff --git a/test.sh b/test_e2e.sh similarity index 89% rename from test.sh rename to test_e2e.sh index aa13106..8993f2b 100755 --- a/test.sh +++ b/test_e2e.sh @@ -13,6 +13,9 @@ function testcase() { function fail() { echo "FAIL: " "$@" + sleep 1 + pkill git-sync || true + ps auxw | grep git-sync exit 1 } @@ -48,9 +51,7 @@ function assert_file_eq() { ######################### # Build it -echo "Building..." -make >/dev/null -GIT_SYNC=./bin/git-sync-amd64 +make container REGISTRY=e2e TAG=$(make -s version) DIR="" for i in $(seq 1 10); do @@ -61,7 +62,17 @@ if [[ -z "$DIR" ]]; then echo "Failed to make a temp dir" exit 1 fi -echo "Test root is $DIR" +echo "test root is $DIR" + +function GIT_SYNC() { + #./bin/amd64/git-sync "$@" + docker run \ + -i \ + -u $(id -u):$(id -g) \ + -v "$DIR":"$DIR" \ + e2e/git-sync-amd64:$(make -s version) \ + "$@" +} REPO="$DIR/repo" mkdir "$REPO" @@ -84,9 +95,10 @@ testcase "head-once" # First sync echo "$TESTCASE" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE" -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --branch=master \ --rev=HEAD \ @@ -96,6 +108,7 @@ $GIT_SYNC \ assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE" +# Wrap up pass # Test default syncing @@ -103,30 +116,33 @@ testcase "default-sync" # First sync echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Move forward echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 2" # Move backward git -C "$REPO" reset -q --hard HEAD^ -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" -kill %1 +# Wrap up +pkill git-sync +wait pass # Test HEAD syncing @@ -134,32 +150,35 @@ testcase "head-sync" # First sync echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --branch=master \ --rev=HEAD \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Move HEAD forward echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 2" # Move HEAD backward git -C "$REPO" reset -q --hard HEAD^ -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" -kill %1 +# Wrap up +pkill git-sync +wait pass # Test branch syncing @@ -170,14 +189,15 @@ git -C "$REPO" checkout -q -b "$BRANCH" echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" git -C "$REPO" checkout -q master -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --branch="$BRANCH" \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" @@ -186,7 +206,7 @@ git -C "$REPO" checkout -q "$BRANCH" echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 2" @@ -194,11 +214,13 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 2" git -C "$REPO" checkout -q "$BRANCH" git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" -kill %1 +# Wrap up +pkill git-sync +wait pass # Test tag syncing @@ -208,14 +230,15 @@ TAG="$TESTCASE"--TAG echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --rev="$TAG" \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" @@ -223,25 +246,27 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1" echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 2" >/dev/null -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 2" # Move the tag backward git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Add something after the tag echo "$TESTCASE 3" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 3" -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" -kill %1 +# Wrap up +pkill git-sync +wait pass # Test cross-branch tag syncing @@ -254,14 +279,15 @@ echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null git -C "$REPO" checkout -q master -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --rev="$TAG" \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" @@ -271,7 +297,7 @@ echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 2" @@ -280,7 +306,7 @@ git -C "$REPO" checkout -q "$BRANCH" git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" @@ -289,7 +315,7 @@ git -C "$REPO" checkout -q "$BRANCH" echo "$TESTCASE 3" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 3" git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" @@ -297,11 +323,13 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1" git -C "$REPO" checkout -q "$BRANCH" git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 3" >/dev/null git -C "$REPO" checkout -q master -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 3" -kill %1 +# Wrap up +pkill git-sync +wait pass # Test rev syncing @@ -310,32 +338,35 @@ testcase "rev-sync" echo "$TESTCASE 1" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 1" REV=$(git -C "$REPO" rev-list -n1 HEAD) -$GIT_SYNC \ +GIT_SYNC \ --logtostderr \ --v=5 \ + --wait=0.1 \ --repo="$REPO" \ --rev="$REV" \ --root="$ROOT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Commit something new echo "$TESTCASE 2" > "$REPO"/file git -C "$REPO" commit -qam "$TESTCASE 2" -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Revert the last change git -C "$REPO" reset -q --hard HEAD^ -sleep 2 +sleep 1 assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$TESTCASE 1" -kill %1 +# Wrap up +pkill git-sync +wait pass -echo "Cleaning up $DIR" +echo "cleaning up $DIR" rm -rf "$DIR"