Last active
August 29, 2015 14:04
-
-
Save detj/80de29fdbfc70c81ef93 to your computer and use it in GitHub Desktop.
Push code to an outside repo, without revealing commits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # The MIT License (MIT) | |
| # Copyright (c) 2014 Debjeet Biswas | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| # copies of the Software, and to permit persons to whom the Software is | |
| # furnished to do so, subject to the following conditions: | |
| # The above copyright notice and this permission notice shall be included in | |
| # all copies or substantial portions of the Software. | |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| # THE SOFTWARE. | |
| # Push the code out to an external repo | |
| # Variables | |
| VERBOSE=0 | |
| OPTIND=1 | |
| TMPDIR=/tmp/pushout | |
| DEFAULT_SOURCE_BRANCH=master | |
| DEFAULT_DEST_BRANCH=master | |
| SOURCE_REPO='' | |
| DEST_REPO='' | |
| TAG='' | |
| # Show usage | |
| function show_help() { | |
| cat << EOF | |
| Usage: pushout -s [email protected]:username/source-repo.git -d [email protected]:username/dest-repo.git -t 1.0 | |
| Push code out to an external repo | |
| -h display this help and exit | |
| -v be verbose | |
| -s source repository | |
| -d destination repository | |
| -t tag | |
| EOF | |
| } | |
| # Log in verbose mode | |
| function log() { | |
| if [ $VERBOSE -eq 1 ] | |
| then | |
| echo $1 | |
| fi | |
| } | |
| # Setup | |
| function setup() { | |
| mkdir -p $TMPDIR | |
| mkdir -p $TMPDIR/source | |
| mkdir -p $TMPDIR/dest | |
| } | |
| # Cleanup | |
| function teardown() { | |
| rm -rf $TMPDIR | |
| } | |
| # Do the actual code push | |
| function transfer() { | |
| cd $TMPDIR/dest | |
| git clone $DEST_REPO $TMPDIR/dest | |
| cd $TMPDIR/source | |
| git clone $SOURCE_REPO $TMPDIR/source | |
| rm -rf .git | |
| cp -r $TMPDIR/source/. $TMPDIR/dest | |
| cd ../dest | |
| git add * | |
| git commit | |
| git push -u origin $DEFAULT_DEST_BRANCH | |
| git tag -a $TAG | |
| git push --tags | |
| } | |
| # Show help and exit | |
| function helpexit() { | |
| show_help | |
| exit 1 | |
| } | |
| # Validate required params | |
| function validate() { | |
| if [ -z $SOURCE_REPO ] | |
| then | |
| helpexit | |
| fi | |
| if [ -z $DEST_REPO ] | |
| then | |
| helpexit | |
| fi | |
| if [ -z $TAG ] | |
| then | |
| helpexit | |
| fi | |
| } | |
| while getopts "hvs:d:t:" opt; do | |
| case "$opt" in | |
| # Show usage and exit | |
| h) | |
| show_help | |
| exit 0 | |
| ;; | |
| # Verbose mode on | |
| v) | |
| VERBOSE=1 | |
| echo 'Verbose mode is on' | |
| ;; | |
| # Read source repository | |
| s) | |
| SOURCE_REPO=$OPTARG | |
| ;; | |
| # Read destination repository | |
| d) | |
| DEST_REPO=$OPTARG | |
| ;; | |
| # Read tag message | |
| t) | |
| TAG=$OPTARG | |
| ;; | |
| esac | |
| done | |
| shift "$((OPTIND-1))" | |
| validate | |
| log "Setting up directory $TMPDIR" | |
| setup | |
| log "Pushing code" | |
| transfer | |
| log "Cleaning up" | |
| teardown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment