Skip to content

Instantly share code, notes, and snippets.

@drAlberT
Last active February 11, 2019 09:34
Show Gist options
  • Save drAlberT/606e0698cb00805efa3a6f1c3ee97a3e to your computer and use it in GitHub Desktop.
Save drAlberT/606e0698cb00805efa3a6f1c3ee97a3e to your computer and use it in GitHub Desktop.

Revisions

  1. drAlberT revised this gist Feb 11, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Quick script to automatically update git submodules on checkout.
    # Save it in the repo `.git/hooks` dir and make it executable

    echo "post-checkout hook: '$1' '$2' '$3'"
    #echo "post-checkout hook: '$1' '$2' '$3'"

    oldRef=$1
    newRef=$2
    @@ -24,5 +24,5 @@ function isChanged {
    if isChanged '.gitmodules'; then
    echo "Change detected to '.gitmodules', updating git submodules."

    git submodule update --init --recursive --force
    git submodule update --init --force # --recursive
    fi
  2. drAlberT revised this gist Feb 9, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash
    #
    # Quick script to automatically update git submodules on checkout.
    # Quick script to automatically update git submodules on checkout.
    # Save it in the repo `.git/hooks` dir and make it executable

    echo "post-checkout hook: '$1' '$2' '$3'"
    @@ -21,8 +21,8 @@ function isChanged {
    git diff --name-only $oldRef $newRef | grep "^$1\$" >/dev/null 2>&1
    }

    if isChanged '.submodules'; then
    echo "Change detected to '.submodules', updating git submodules."
    if isChanged '.gitmodules'; then
    echo "Change detected to '.gitmodules', updating git submodules."

    git submodule update --init --recursive --force
    fi
  3. drAlberT created this gist Feb 9, 2019.
    28 changes: 28 additions & 0 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env bash
    #
    # Quick script to automatically update git submodules on checkout.
    # Save it in the repo `.git/hooks` dir and make it executable

    echo "post-checkout hook: '$1' '$2' '$3'"

    oldRef=$1
    newRef=$2

    # Exit early if the local branch is behind the remote
    LOCAL=$(git rev-parse @)
    REMOTE=$(git rev-parse @{u} 2> /dev/null)
    BASE=$(git merge-base @ @{u} 2> /dev/null)

    if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then
    exit 0
    fi

    function isChanged {
    git diff --name-only $oldRef $newRef | grep "^$1\$" >/dev/null 2>&1
    }

    if isChanged '.submodules'; then
    echo "Change detected to '.submodules', updating git submodules."

    git submodule update --init --recursive --force
    fi