Skip to content

Instantly share code, notes, and snippets.

@redthor
Last active November 13, 2017 12:29
Show Gist options
  • Select an option

  • Save redthor/93b2d59f40782c09c7e7d8873049dc09 to your computer and use it in GitHub Desktop.

Select an option

Save redthor/93b2d59f40782c09c7e7d8873049dc09 to your computer and use it in GitHub Desktop.

Revisions

  1. redthor revised this gist Nov 13, 2017. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions pre-push
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    remote="$1"
    url="$2"

    z40=0000000000000000000000000000000000000000

    # Don't bother unless this is origin
    if [ "$remote" != "origin" ]
    then
    exit 0
    fi

    # refs/heads/master 67890 refs/heads/foreign 12345
    # Need
    # git push <remote-many-repo> <target split.sh branch>:<remote-many-repo-branch>
    # e.g. `git push svc-repo refs/heads/svc:master`

    #
    # If _this_ branch is `refs/heads/GLOWSYS-284-int-fix` then:
    # `git push svc-repo refs/heads/svc:GLOWSYS-284-int-fix`
    #

    while read local_ref local_sha remote_ref remote_sha
    do
    if [ "$local_sha" = $z40 ]
    then
    # Handle delete
    :
    else
    # refs/heads/GLOWSYS-284-int-fix -> GLOWSYS-284-int-fix
    branchName=${local_ref##*/}
    ../splitsh-lite --prefix svc/ --target refs/heads/svc --progress
    git push svc-repo refs/heads/svc:$branchName
    fi
    done

    exit 0
  2. redthor created this gist Nov 13, 2017.
    44 changes: 44 additions & 0 deletions split.sh-tests.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    wget https://github.com/splitsh/lite/releases/download/v1.0.1/lite_linux_amd64.tar.gz
    tar xzf *gz

    # Base dir
    mkdir mono
    cd mono
    git init
    echo -e "## README\nmonorepo" > README.md
    git add .
    git commit -m 'Initial commit'

    # Split of svc dir under mono
    mkdir svc
    echo -e '## README\nsvc' > svc/README.md
    git add .
    git commit -m 'Initial commit for svc'

    # The split
    ../splitsh-lite --prefix svc/ --target refs/heads/svc --progress

    # To test locally and save on network requests
    git init --bare ../svc.git
    git remote add svc-repo ../svc.git/
    git fetch svc-repo
    git push svc-repo svc:master

    # Check to see all is well
    cd ..
    git clone svc.git svc
    cd svc
    ls -l
    git status

    # Test again
    cd ../mono
    echo "Some changes" >> svc/README.md
    git commit -am 'Update svc README'
    ../splitsh-lite --prefix svc/ --target refs/heads/svc --progress
    git push svc-repo svc:master

    # Back in svc
    cd -
    git pull
    # should be all up to date