File size: 2,917 Bytes
cd53438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# Sync tools/validation/ from the upstream GitLab branch.
#
# Run from the repo root:
#   bash tools/validation/_sync.sh
#
# After running, review the diff, bump the pin block in
# tools/validation/UPSTREAM.md, and commit.

set -euo pipefail

UPSTREAM_URL="https://gitlab-master.nvidia.com/omniverse/kit-extensions/simready-explorer.git"
UPSTREAM_BRANCH="dev/dloginowski/validation-reporting"
UPSTREAM_PATH="validation"
LOCAL_PATH="tools/validation"
KEEP=(UPSTREAM.md _sync.sh)

if [[ ! -d "${LOCAL_PATH}" ]]; then
  echo "expected ${LOCAL_PATH} to exist; are you in the repo root?" >&2
  exit 1
fi

# Compare current pin to upstream HEAD.
current_pin="$(grep -oE 'upstream_sha:\s*[0-9a-f]+' "${LOCAL_PATH}/UPSTREAM.md" \
                | awk '{print $2}' | head -n1 || true)"
upstream_sha="$(git ls-remote "${UPSTREAM_URL}" "refs/heads/${UPSTREAM_BRANCH}" \
                | awk '{print $1}')"

if [[ -z "${upstream_sha}" ]]; then
  echo "could not resolve upstream branch SHA — check network / auth" >&2
  exit 2
fi

echo "current pin:   ${current_pin:-(unset)}"
echo "upstream HEAD: ${upstream_sha}"

if [[ "${current_pin}" == "${upstream_sha}" ]]; then
  echo "already in sync — nothing to do"
  exit 0
fi

tmpdir="$(mktemp -d)"
trap 'rm -rf "${tmpdir}"' EXIT

echo ">> shallow-clone upstream"
git clone --depth 50 --branch "${UPSTREAM_BRANCH}" --single-branch \
  "${UPSTREAM_URL}" "${tmpdir}/upstream" >/dev/null

# How many commits ahead of the current pin (best-effort; falls back to "?")
ahead="?"
if [[ -n "${current_pin}" ]]; then
  if git -C "${tmpdir}/upstream" cat-file -e "${current_pin}" 2>/dev/null; then
    ahead="$(git -C "${tmpdir}/upstream" rev-list --count "${current_pin}..HEAD")"
  fi
fi
echo "commits ahead of pin: ${ahead}"

upstream_dir="${tmpdir}/upstream/${UPSTREAM_PATH}"
if [[ ! -d "${upstream_dir}" ]]; then
  echo "upstream ${UPSTREAM_PATH}/ missing in branch ${UPSTREAM_BRANCH}" >&2
  exit 3
fi

echo ">> rsync upstream → ${LOCAL_PATH}"
# Stash KEEP files so rsync --delete doesn't remove them.
keep_stash="$(mktemp -d)"
for f in "${KEEP[@]}"; do
  if [[ -f "${LOCAL_PATH}/${f}" ]]; then
    cp -p "${LOCAL_PATH}/${f}" "${keep_stash}/${f}"
  fi
done

rsync -a --delete "${upstream_dir}/" "${LOCAL_PATH}/"

for f in "${KEEP[@]}"; do
  if [[ -f "${keep_stash}/${f}" ]]; then
    cp -p "${keep_stash}/${f}" "${LOCAL_PATH}/${f}"
  fi
done
rm -rf "${keep_stash}"

echo
echo ">> changes:"
git -c color.ui=always diff --stat -- "${LOCAL_PATH}" | tail -20 || true

cat <<EOF

Sync staged. Next steps:

  1. Bump the pin block in ${LOCAL_PATH}/UPSTREAM.md:

       upstream_sha: ${upstream_sha}
       synced_at:    $(date -u +%Y-%m-%d)
       synced_by:    \$(git config user.name)

  2. Review the diff:    git diff -- ${LOCAL_PATH}
  3. Commit:             git add ${LOCAL_PATH} && git commit -m "Sync tools/validation/ from upstream ${upstream_sha:0:12}"
EOF