Skip to content

Instantly share code, notes, and snippets.

@tomjenkinson
Last active December 25, 2015 04:19

Revisions

  1. tomjenkinson revised this gist Feb 3, 2014. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions gitreqrebase
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ then
    exit
    fi

    git status | grep "Your branch\|Untracked\|Changes not staged"
    git status | grep "Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $2 is clean before applying
    exit -1
    @@ -29,43 +29,43 @@ reponame=`git remote -v | grep origin | grep push | sed "s#.*/\(.*\)\.git.*#\1#g
    gitreqnumber=$1
    shift

    rm -f $gitreqnumber.tmp
    wget --no-check-certificate https://github.com/$upstreamname/$reponame/pull/$gitreqnumber -O $gitreqnumber.tmp
    rm -f $gitreqnumber
    wget --no-check-certificate https://github.com/$upstreamname/$reponame/pull/$gitreqnumber -O $gitreqnumber
    if [ $? -ne 0 ]; then
    echo Could not download pull req info
    exit
    echo "Could not download pull req info"
    exit -1
    fi

    username=$(grep "opened this pull request" $gitreqnumber.tmp | sed 's#.*href="/\(.*\)">.*</a> open.*#\1#')
    username=$(grep "by .* · Pull" $pullNumber | sed 's#.*by \(.*\) · Pull.*#\1#')
    git remote -v | grep origin | grep $username > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "This is not one of your pull requests"
    rm $gitreqnumber.tmp
    rm $gitreqnumber
    exit 0
    fi

    branchname=$(grep "span.*$username.*css-truncate-target" $gitreqnumber.tmp | sed 's#.*">\(.*\)<.*#\1#')
    branchname=$(grep "span.*$username.*css-truncate-target" $gitreqnumber | sed 's#.*">\(.*\)<.*#\1#')
    expr length $branchname > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "Could not find branch name, assuming first word of title!"
    branchname=$(grep "<title>" 1 | sed 's#.*<title>\([a-zA-Z0-9\-]*\) .*#\1#')
    expr length $branchname > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "Could not find branch name, aborting"
    rm $gitreqnumber.tmp
    rm $gitreqnumber
    exit -1
    fi
    fi

    rm $gitreqnumber.tmp
    rm $gitreqnumber

    upstreamBranch=$1
    shift

    git status | grep "Your branch\|Untracked\|Changes not staged"
    git status | grep "Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $upstreamBranch is clean before applying
    exit
    exit -1
    fi

    git checkout $branchname
  2. tomjenkinson revised this gist Oct 10, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gitreqrebase
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,7 @@ fi
    username=$(grep "opened this pull request" $gitreqnumber.tmp | sed 's#.*href="/\(.*\)">.*</a> open.*#\1#')
    git remote -v | grep origin | grep $username > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "This is not one of your pull requests"
    rm $gitreqnumber.tmp
    exit 0
    fi
  3. tomjenkinson revised this gist Oct 10, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gitreqrebase
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,7 @@ fi
    username=$(grep "opened this pull request" $gitreqnumber.tmp | sed 's#.*href="/\(.*\)">.*</a> open.*#\1#')
    git remote -v | grep origin | grep $username > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    rm $gitreqnumber.tmp
    exit 0
    fi

    @@ -50,6 +51,7 @@ if [ "$?" -ne 0 ]; then
    expr length $branchname > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "Could not find branch name, aborting"
    rm $gitreqnumber.tmp
    exit -1
    fi
    fi
  4. tomjenkinson revised this gist Oct 10, 2013. 2 changed files with 88 additions and 56 deletions.
    56 changes: 0 additions & 56 deletions gitrebase
    Original file line number Diff line number Diff line change
    @@ -1,56 +0,0 @@
    #!/bin/bash

    git remote | grep upstream > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo This script assumes you have upstream set as the repo to hand reqs in
    exit
    fi

    if [ ! -d .git ]; then
    echo This script assumes you are in the root of a repo clone
    exit
    fi

    if [ $# -lt 2 ]
    then
    echo "Need pull number and branch"
    exit
    fi

    branchname=$1
    shift
    upstreamBranch=$1
    shift

    git status | grep "Your branch\|Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $upstreamBranch is clean before applying
    exit
    fi

    #git remote -v | grep origin | grep $username > /dev/null 2>&1
    #if [ "$?" -ne 0 ]; then
    # exit 0
    #fi

    git checkout $branchname
    if [ "$?" -ne 0 ]; then
    echo "Branch $branchname did not exist"
    exit -1
    fi

    git fetch upstream
    echo "Trying to rebase $branchname against $upstreamBranch"
    git pull --rebase --ff-only upstream $upstreamBranch
    if [ $? -ne 0 ]; then
    git rebase --abort
    echo "Could not perform rebase"
    exit -1
    fi

    echo "Attempting to push"
    git push origin $branchname "$@"
    if [ $? -ne 0 ]; then
    echo "Could not push to upstream"
    exit -1
    fi
    88 changes: 88 additions & 0 deletions gitreqrebase
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    #!/bin/bash

    git remote | grep upstream > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo This script assumes you have upstream set as the repo to hand reqs in
    exit
    fi

    if [ ! -d .git ]; then
    echo This script assumes you are in the root of a repo clone
    exit
    fi

    if [ $# -lt 2 ]
    then
    echo "Need pull number and branch"
    exit
    fi

    git status | grep "Your branch\|Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $2 is clean before applying
    exit -1
    fi

    upstreamname=`git remote -v | grep upstream | grep fetch | sed "s#upstream.*github.com[:/]\(.*\)/.*#\1#"`
    reponame=`git remote -v | grep origin | grep push | sed "s#.*/\(.*\)\.git.*#\1#g"`

    gitreqnumber=$1
    shift

    rm -f $gitreqnumber.tmp
    wget --no-check-certificate https://github.com/$upstreamname/$reponame/pull/$gitreqnumber -O $gitreqnumber.tmp
    if [ $? -ne 0 ]; then
    echo Could not download pull req info
    exit
    fi

    username=$(grep "opened this pull request" $gitreqnumber.tmp | sed 's#.*href="/\(.*\)">.*</a> open.*#\1#')
    git remote -v | grep origin | grep $username > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    exit 0
    fi

    branchname=$(grep "span.*$username.*css-truncate-target" $gitreqnumber.tmp | sed 's#.*">\(.*\)<.*#\1#')
    expr length $branchname > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "Could not find branch name, assuming first word of title!"
    branchname=$(grep "<title>" 1 | sed 's#.*<title>\([a-zA-Z0-9\-]*\) .*#\1#')
    expr length $branchname > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo "Could not find branch name, aborting"
    exit -1
    fi
    fi

    rm $gitreqnumber.tmp

    upstreamBranch=$1
    shift

    git status | grep "Your branch\|Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $upstreamBranch is clean before applying
    exit
    fi

    git checkout $branchname
    if [ "$?" -ne 0 ]; then
    echo "Branch $branchname did not exist"
    exit -1
    fi

    git fetch upstream
    echo "Trying to rebase $branchname against $upstreamBranch"
    git pull --rebase --ff-only upstream $upstreamBranch
    if [ $? -ne 0 ]; then
    git rebase --abort
    echo "Could not perform rebase"
    exit -1
    fi

    echo "Attempting to push"
    git push origin $branchname "$@"
    if [ $? -ne 0 ]; then
    echo "Could not push to upstream"
    exit -1
    fi
  5. tomjenkinson renamed this gist Oct 10, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. tomjenkinson created this gist Oct 10, 2013.
    56 changes: 56 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/bin/bash

    git remote | grep upstream > /dev/null 2>&1
    if [ "$?" -ne 0 ]; then
    echo This script assumes you have upstream set as the repo to hand reqs in
    exit
    fi

    if [ ! -d .git ]; then
    echo This script assumes you are in the root of a repo clone
    exit
    fi

    if [ $# -lt 2 ]
    then
    echo "Need pull number and branch"
    exit
    fi

    branchname=$1
    shift
    upstreamBranch=$1
    shift

    git status | grep "Your branch\|Untracked\|Changes not staged"
    if [ $? -eq 0 ]; then
    echo Ensure working $upstreamBranch is clean before applying
    exit
    fi

    #git remote -v | grep origin | grep $username > /dev/null 2>&1
    #if [ "$?" -ne 0 ]; then
    # exit 0
    #fi

    git checkout $branchname
    if [ "$?" -ne 0 ]; then
    echo "Branch $branchname did not exist"
    exit -1
    fi

    git fetch upstream
    echo "Trying to rebase $branchname against $upstreamBranch"
    git pull --rebase --ff-only upstream $upstreamBranch
    if [ $? -ne 0 ]; then
    git rebase --abort
    echo "Could not perform rebase"
    exit -1
    fi

    echo "Attempting to push"
    git push origin $branchname "$@"
    if [ $? -ne 0 ]; then
    echo "Could not push to upstream"
    exit -1
    fi