Switch to rev-parse
This handles non-annotated tags, which were not handled well before. It does mean that we use the hash of the (annotated) tag object instead of the commit, but that seems OK. Added a test case.
This commit is contained in:
parent
cb1ef896a9
commit
40e188fb26
|
|
@ -357,7 +357,7 @@ func cloneRepo(repo, branch, rev string, depth int, gitRoot string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashForRev(rev, gitRoot string) (string, error) {
|
func hashForRev(rev, gitRoot string) (string, error) {
|
||||||
output, err := runCommand(gitRoot, "git", "rev-list", "-n1", rev)
|
output, err := runCommand(gitRoot, "git", "rev-parse", rev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -365,8 +365,8 @@ func hashForRev(rev, gitRoot string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func revIsHash(rev, gitRoot string) (bool, error) {
|
func revIsHash(rev, gitRoot string) (bool, error) {
|
||||||
// If a rev is a tag name or HEAD, rev-list will produce the git hash. If
|
// If rev is a tag name or HEAD, rev-parse will produce the git hash. If
|
||||||
// it is already a git hash, the output will be the same hash. Of course, a
|
// rev is already a git hash, the output will be the same hash. Of course, a
|
||||||
// user could specify "abc" and match "abcdef12345678", so we just do a
|
// user could specify "abc" and match "abcdef12345678", so we just do a
|
||||||
// prefix match.
|
// prefix match.
|
||||||
output, err := hashForRev(rev, gitRoot)
|
output, err := hashForRev(rev, gitRoot)
|
||||||
|
|
@ -426,7 +426,7 @@ func getRevs(localDir, branch, rev string) (string, string, error) {
|
||||||
if rev == "HEAD" {
|
if rev == "HEAD" {
|
||||||
ref = "refs/heads/" + branch
|
ref = "refs/heads/" + branch
|
||||||
} else {
|
} else {
|
||||||
ref = "refs/tags/" + rev + "^{}"
|
ref = "refs/tags/" + rev
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out what hash the remote resolves ref to.
|
// Figure out what hash the remote resolves ref to.
|
||||||
|
|
|
||||||
50
test_e2e.sh
50
test_e2e.sh
|
|
@ -56,9 +56,9 @@ function finish() {
|
||||||
|
|
||||||
trap finish INT EXIT
|
trap finish INT EXIT
|
||||||
|
|
||||||
#########################
|
# #####################
|
||||||
# main
|
# main
|
||||||
#########################
|
# #####################
|
||||||
|
|
||||||
# Build it
|
# Build it
|
||||||
make container REGISTRY=e2e TAG=$(make -s version)
|
make container REGISTRY=e2e TAG=$(make -s version)
|
||||||
|
|
@ -248,6 +248,52 @@ TAG="$TESTCASE"--TAG
|
||||||
# First sync
|
# First sync
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
|
git -C "$REPO" tag -f "$TAG" >/dev/null
|
||||||
|
GIT_SYNC \
|
||||||
|
--logtostderr \
|
||||||
|
--v=5 \
|
||||||
|
--wait=0.1 \
|
||||||
|
--repo="$REPO" \
|
||||||
|
--rev="$TAG" \
|
||||||
|
--root="$ROOT" \
|
||||||
|
--dest="link" > "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
|
sleep 3
|
||||||
|
assert_link_exists "$ROOT"/link
|
||||||
|
assert_file_exists "$ROOT"/link/file
|
||||||
|
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
||||||
|
# Add something and move the tag forward
|
||||||
|
echo "$TESTCASE 2" > "$REPO"/file
|
||||||
|
git -C "$REPO" commit -qam "$TESTCASE 2"
|
||||||
|
git -C "$REPO" tag -f "$TAG" >/dev/null
|
||||||
|
sleep 3
|
||||||
|
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 -f "$TAG" >/dev/null
|
||||||
|
sleep 3
|
||||||
|
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 3
|
||||||
|
assert_link_exists "$ROOT"/link
|
||||||
|
assert_file_exists "$ROOT"/link/file
|
||||||
|
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
||||||
|
# Wrap up
|
||||||
|
remove_sync_container
|
||||||
|
wait
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Test tag syncing with annotated tags
|
||||||
|
testcase "tag-sync-annotated"
|
||||||
|
TAG="$TESTCASE"--TAG
|
||||||
|
# First sync
|
||||||
|
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" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--logtostderr \
|
--logtostderr \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue