From d4c9827fcf7b3a98fdf58cbfe163334062fdbc6c Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 5 Nov 2019 14:07:38 -0700 Subject: [PATCH 1/5] travis: Unshallow submodules. --- .travis/fixup-git.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/fixup-git.sh b/.travis/fixup-git.sh index 916dd6da..6fbef82b 100755 --- a/.travis/fixup-git.sh +++ b/.travis/fixup-git.sh @@ -52,6 +52,7 @@ echo "" echo "- Fetching non shallow to get git version" echo "---------------------------------------------" git fetch origin --unshallow || true +git fetch origin --unshallow --recurse-submodules=yes || true git fetch origin --tags TRAVIS_COMMIT_ACTUAL=$(git log --pretty=format:'%H' -n 1) From f4ffb0376871c2cde8590db7729696adf5f11641 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Tue, 5 Nov 2019 14:16:11 -0700 Subject: [PATCH 2/5] travis: Update add-local-submodule scripts. * Deal with shallow cloned submodules. * Sync the submodule remote first. * Use https rather than git:// * Exit if the remote origin doesn't exist. --- ...module.sh => add-local-submodule-inner.sh} | 69 ++++++++++++------- .travis/add-local-submodules.sh | 29 ++++++++ .travis/fixup-git.sh | 15 ++-- 3 files changed, 78 insertions(+), 35 deletions(-) rename .travis/{add-local-submodule.sh => add-local-submodule-inner.sh} (60%) create mode 100755 .travis/add-local-submodules.sh diff --git a/.travis/add-local-submodule.sh b/.travis/add-local-submodule-inner.sh similarity index 60% rename from .travis/add-local-submodule.sh rename to .travis/add-local-submodule-inner.sh index 906057ee..924985d6 100755 --- a/.travis/add-local-submodule.sh +++ b/.travis/add-local-submodule-inner.sh @@ -15,9 +15,10 @@ set -e echo USER_SLUG="$1" SUBMODULE="$2" +SHA1="$3" REV=$(git rev-parse HEAD) -echo "Submodule $SUBMODULE" +echo "Submodule $SUBMODULE @ '$SHA1'" # Get the pull request info REQUEST_USER="$(echo $USER_SLUG | perl -pe 's|^([^/]*)/.*|\1|')" @@ -29,6 +30,33 @@ echo "Request repo is '$REQUEST_REPO'". # Get current origin from git ORIGIN_URL="$(git config -f .gitmodules submodule.$SUBMODULE.url)" #ORIGIN_URL="$(git remote get-url origin)" + +# Check the origin repo exists +echo -n "Origin's repo would be '$ORIGIN_URL' " +if git ls-remote --exit-code --heads "$ORIGIN_URL" > /dev/null 2>&1; then + echo "which exists!" +else + echo "which does *not* exist!" + exit 1 +fi + +# If submodule doesn't exist, clone directly from the users repo +if [ ! -e $SUBMODULE/.git ]; then + echo "Cloning from repo '$ORIGIN_URL'" + git clone $ORIGIN_URL $SUBMODULE --origin origin +fi +( + cd $SUBMODULE + git remote rm origin >/dev/null 2>&1 || true + git remote add origin $ORIGIN_URL + + if [ $(git rev-parse --is-shallow-repository) != "false" ]; then + git fetch origin --no-recurse-submodules --unshallow + fi + git fetch origin --no-recurse-submodules +) + +# Check if this origin is on github? if echo $ORIGIN_URL | grep -q "github.com"; then echo "Found github" else @@ -45,48 +73,39 @@ ORIGIN_REPO="$(echo $ORIGIN_SLUG | perl -pe 's|.*?/([^/]*)$|\1|')" echo "Origin user is '$ORIGIN_USER'" echo "Origin repo is '$ORIGIN_REPO'" -USER_URL="git://github.com/$REQUEST_USER/$ORIGIN_REPO.git" - # Check if the user's repo exists +USER_URL="https://github.com/$REQUEST_USER/$ORIGIN_REPO.git" echo -n "User's repo would be '$USER_URL' " if git ls-remote --exit-code --heads "$USER_URL" > /dev/null 2>&1; then echo "which exists!" + + ( + cd $SUBMODULE + git remote rm user >/dev/null 2>&1 || true + git remote add user $USER_URL + + git fetch user --no-recurse-submodules + ) else echo "which does *not* exist!" - USER_URL="$ORIGIN_URL" fi -# If submodule doesn't exist, clone directly from the users repo -if [ ! -e $SUBMODULE/.git ]; then - echo "Cloning '$ORIGIN_REPO' from repo '$USER_URL'" - git clone $USER_URL $SUBMODULE --origin user -fi -# If the submodule does exist, add a new remote. +# Checkout to the correct SHA1 value - which may come from origin or user. ( cd $SUBMODULE - - git remote rm user >/dev/null 2>&1 || true - if [ "$USER_URL" != "$ORIGIN_URL" ]; then - git remote add user $USER_URL - git fetch user - fi - - git remote rm origin >/dev/null 2>&1 || true - git remote add origin $ORIGIN_URL - git fetch origin + git reset --hard "$SHA1" --recurse-submodules=no ) -# Checkout the submodule at the right revision -git submodule update --init $SUBMODULE - # Call ourselves recursively. ( cd $SUBMODULE + # Checkout the submodule at the right revision + git submodule sync git submodule status echo - git submodule status | while read SHA1 MODULE_PATH DESC + git submodule status | sed -e's/^.//' | while read SHA1 MODULE_PATH DESC do - "$SCRIPT_SRC" "$USER_SLUG" "$MODULE_PATH" + "$SCRIPT_SRC" "$USER_SLUG" "$MODULE_PATH" "$SHA1" done exit 0 ) || exit 1 diff --git a/.travis/add-local-submodules.sh b/.travis/add-local-submodules.sh new file mode 100755 index 00000000..b432d367 --- /dev/null +++ b/.travis/add-local-submodules.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +# Disable prompting for passwords - works with git version 2.3 or above +export GIT_TERMINAL_PROMPT=0 + +if [ z$1 == z ]; then + echo "Missing USER_SLUG as first argument!" + exit 1 +fi +export USER_SLUG=$1 + +echo "" +echo "" +echo "" +echo "- Using local version of submodules (if they exist)" +echo "---------------------------------------------" +git submodule status +echo +git submodule status | sed -e's/^.//' | while read SHA1 MODULE_PATH DESC +do + "$PWD/.travis/add-local-submodule-inner.sh" "$USER_SLUG" "$MODULE_PATH" "$SHA1" +done +echo +git submodule status --recursive +echo +git submodule foreach --recursive 'git remote -v; echo' +exit 0 diff --git a/.travis/fixup-git.sh b/.travis/fixup-git.sh index 6fbef82b..156eede9 100755 --- a/.travis/fixup-git.sh +++ b/.travis/fixup-git.sh @@ -51,8 +51,9 @@ echo "" echo "" echo "- Fetching non shallow to get git version" echo "---------------------------------------------" -git fetch origin --unshallow || true -git fetch origin --unshallow --recurse-submodules=yes || true +if git rev-parse --is-shallow-repository; then + git fetch origin --unshallow +fi git fetch origin --tags TRAVIS_COMMIT_ACTUAL=$(git log --pretty=format:'%H' -n 1) @@ -100,10 +101,7 @@ if [ z"$TRAVIS_PULL_REQUEST_SLUG" != z ]; then echo "" echo "- Using pull request version of submodules (if they exist)" echo "---------------------------------------------" - git submodule status | while read SHA1 MODULE_PATH - do - "$PWD/.travis/add-local-submodule.sh" "$TRAVIS_PULL_REQUEST_SLUG" "$MODULE_PATH" - done + $PWD/.travis/add-local-submodules.sh $TRAVIS_PULL_REQUEST_SLUG echo "---------------------------------------------" git submodule foreach --recursive 'git remote -v; echo' echo "---------------------------------------------" @@ -115,10 +113,7 @@ if [ z"$TRAVIS_REPO_SLUG" != z ]; then echo "" echo "- Using local version of submodules (if they exist)" echo "---------------------------------------------" - git submodule status | while read SHA1 MODULE_PATH DESC - do - "$PWD/.travis/add-local-submodule.sh" "$TRAVIS_REPO_SLUG" "$MODULE_PATH" - done + $PWD/.travis/add-local-submodules.sh $TRAVIS_REPO_SLUG echo "---------------------------------------------" git submodule foreach --recursive 'git remote -v; echo' echo "---------------------------------------------" From 83d348b5e48eabd316bb4314b1331e4ea89ecd7d Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Wed, 6 Nov 2019 09:04:55 -0700 Subject: [PATCH 3/5] Add back git submodule --init --- .travis/add-local-submodule-inner.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis/add-local-submodule-inner.sh b/.travis/add-local-submodule-inner.sh index 924985d6..1b5d69d1 100755 --- a/.travis/add-local-submodule-inner.sh +++ b/.travis/add-local-submodule-inner.sh @@ -96,6 +96,8 @@ fi git reset --hard "$SHA1" --recurse-submodules=no ) +git submodule update --init $SUBMODULE + # Call ourselves recursively. ( cd $SUBMODULE From ccbb875dd9bbaf12b5f6ea3a3008e026122cb90c Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Wed, 6 Nov 2019 10:04:47 -0700 Subject: [PATCH 4/5] Always init the submodule, even if not on github. --- .travis/add-local-submodule-inner.sh | 70 ++++++++++++---------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/.travis/add-local-submodule-inner.sh b/.travis/add-local-submodule-inner.sh index 1b5d69d1..67dfbc2c 100755 --- a/.travis/add-local-submodule-inner.sh +++ b/.travis/add-local-submodule-inner.sh @@ -30,21 +30,40 @@ echo "Request repo is '$REQUEST_REPO'". # Get current origin from git ORIGIN_URL="$(git config -f .gitmodules submodule.$SUBMODULE.url)" #ORIGIN_URL="$(git remote get-url origin)" +if echo $ORIGIN_URL | grep -q "github.com"; then + echo "Found github" + + ORIGIN_SLUG=$(echo $ORIGIN_URL | perl -pe 's|.*github.com/(.*?)(.git)?$|\1|') + echo "Origin slug is '$ORIGIN_SLUG'" + + ORIGIN_USER="$(echo $ORIGIN_SLUG | perl -pe 's|^([^/]*)/.*|\1|')" + ORIGIN_REPO="$(echo $ORIGIN_SLUG | perl -pe 's|.*?/([^/]*)$|\1|')" + + echo "Origin user is '$ORIGIN_USER'" + echo "Origin repo is '$ORIGIN_REPO'" + + USER_URL="https://github.com/$REQUEST_USER/$ORIGIN_REPO.git" -# Check the origin repo exists -echo -n "Origin's repo would be '$ORIGIN_URL' " -if git ls-remote --exit-code --heads "$ORIGIN_URL" > /dev/null 2>&1; then - echo "which exists!" + # Check if the user's repo exists + echo -n "User's repo would be '$USER_URL' " + if git ls-remote --exit-code --heads "$USER_URL" > /dev/null 2>&1; then + echo "which exists!" + else + echo "which does *not* exist!" + USER_URL="$ORIGIN_URL" + fi else - echo "which does *not* exist!" - exit 1 + echo "Did not find github" + USER_URL="$ORIGIN_URL" fi # If submodule doesn't exist, clone directly from the users repo if [ ! -e $SUBMODULE/.git ]; then - echo "Cloning from repo '$ORIGIN_URL'" - git clone $ORIGIN_URL $SUBMODULE --origin origin + echo "Cloning '$ORIGIN_REPO' from repo '$USER_URL'" + git clone $USER_URL $SUBMODULE --origin user --branch $SHA1 fi + +# If the submodule does exist, add a new remote. ( cd $SUBMODULE git remote rm origin >/dev/null 2>&1 || true @@ -54,41 +73,13 @@ fi git fetch origin --no-recurse-submodules --unshallow fi git fetch origin --no-recurse-submodules -) - -# Check if this origin is on github? -if echo $ORIGIN_URL | grep -q "github.com"; then - echo "Found github" -else - echo "Did not find github, skipping" - exit 0 -fi - -ORIGIN_SLUG=$(echo $ORIGIN_URL | perl -pe 's|.*github.com/(.*?)(.git)?$|\1|') -echo "Origin slug is '$ORIGIN_SLUG'" - -ORIGIN_USER="$(echo $ORIGIN_SLUG | perl -pe 's|^([^/]*)/.*|\1|')" -ORIGIN_REPO="$(echo $ORIGIN_SLUG | perl -pe 's|.*?/([^/]*)$|\1|')" - -echo "Origin user is '$ORIGIN_USER'" -echo "Origin repo is '$ORIGIN_REPO'" -# Check if the user's repo exists -USER_URL="https://github.com/$REQUEST_USER/$ORIGIN_REPO.git" -echo -n "User's repo would be '$USER_URL' " -if git ls-remote --exit-code --heads "$USER_URL" > /dev/null 2>&1; then - echo "which exists!" - - ( - cd $SUBMODULE + if [ "$USER_URL" != "$ORIGIN_URL" ]; then git remote rm user >/dev/null 2>&1 || true git remote add user $USER_URL - git fetch user --no-recurse-submodules - ) -else - echo "which does *not* exist!" -fi + fi +) # Checkout to the correct SHA1 value - which may come from origin or user. ( @@ -96,6 +87,7 @@ fi git reset --hard "$SHA1" --recurse-submodules=no ) +# Init the submodule git submodule update --init $SUBMODULE # Call ourselves recursively. From b0117dfb7be5bc7c8e04fc010a3ffb5fd0867921 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Wed, 6 Nov 2019 10:57:46 -0700 Subject: [PATCH 5/5] Make sure to get the origin first. Only add the user version afterwards. --- .travis/add-local-submodule-inner.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis/add-local-submodule-inner.sh b/.travis/add-local-submodule-inner.sh index 67dfbc2c..1da263f6 100755 --- a/.travis/add-local-submodule-inner.sh +++ b/.travis/add-local-submodule-inner.sh @@ -59,27 +59,34 @@ fi # If submodule doesn't exist, clone directly from the users repo if [ ! -e $SUBMODULE/.git ]; then - echo "Cloning '$ORIGIN_REPO' from repo '$USER_URL'" - git clone $USER_URL $SUBMODULE --origin user --branch $SHA1 + echo "Cloning '$ORIGIN_REPO' from repo '$ORIGIN_URL'" + git clone $ORIGIN_URL $SUBMODULE --origin origin +else + ( + cd $SUBMODULE + git remote rm origin >/dev/null 2>&1 || true + git remote add origin $ORIGIN_URL + ) fi -# If the submodule does exist, add a new remote. +# Fetch origin and make sure the submodule isn't shallow. ( cd $SUBMODULE - git remote rm origin >/dev/null 2>&1 || true - git remote add origin $ORIGIN_URL - if [ $(git rev-parse --is-shallow-repository) != "false" ]; then git fetch origin --no-recurse-submodules --unshallow fi git fetch origin --no-recurse-submodules +) - if [ "$USER_URL" != "$ORIGIN_URL" ]; then +# Add the user remote and fetch it. +if [ "$USER_URL" != "$ORIGIN_URL" ]; then + ( + cd $SUBMODULE git remote rm user >/dev/null 2>&1 || true git remote add user $USER_URL git fetch user --no-recurse-submodules - fi -) + ) +fi # Checkout to the correct SHA1 value - which may come from origin or user. (