Skip to content

Instantly share code, notes, and snippets.

@Shamar
Created July 28, 2015 00:43
Show Gist options
  • Save Shamar/1f818b47138b0bc21c29 to your computer and use it in GitHub Desktop.
Save Shamar/1f818b47138b0bc21c29 to your computer and use it in GitHub Desktop.

Revisions

  1. Shamar created this gist Jul 28, 2015.
    23 changes: 23 additions & 0 deletions branch2patch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash

    if [ ! -d ".git" ]; then
    echo "`pwd` is not a git repo"
    exit 3
    fi

    STATUS=`git status -b --porcelain`
    STATUSL=`git status -b --porcelain|wc -l`
    BRANCH=`git status -b --porcelain | head -1|tr -d '# '`
    ROOT=`git rev-parse --show-toplevel`

    if [ "$STATUSL" -gt "1" ]; then
    echo "branch $BRANCH not clean"
    exit 1
    fi

    if [ "$BRANCH" == "master" ]; then
    echo "cannot create patch from master branch"
    exit 2
    fi

    git diff master..$BRANCH > $ROOT/../patches/$BRANCH.patch
    28 changes: 28 additions & 0 deletions patch2commit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash

    PATCHNAME="$1"
    ROOT=`git rev-parse --show-toplevel`

    if [ "$PATCHNAME" == "" ]; then
    echo "missing patch/branch name"
    exit 1
    fi

    if [ ! -f "$ROOT/../../HarveyOS-Shamar/patches/$PATCHNAME.patch" ]; then
    echo "cannot find HarveyOS-Shamar/patches/$PATCHNAME.patch"
    exit 2
    fi

    git checkout -B $PATCHNAME master
    git apply "$ROOT/../../HarveyOS-Shamar/patches/$PATCHNAME.patch"
    git add .
    git add -A
    if git commit -s; then
    git push
    else
    git clean -d -x -f
    git reset HEAD
    git apply --reverse "$ROOT/../../HarveyOS-Shamar/patches/$PATCHNAME.patch"
    fi

    echo $PATCHNAME