Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/tmp
tmp
Gemfile.lock
16 changes: 16 additions & 0 deletions bin/git-branch-override
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Removes a branch specified as temp of another
if [ "$1" == "" ]; then
echo -e "ERROR: Must pass branch name." 1>&2
exit 1
fi

if [ "$2" == "" ]; then
echo -e "ERROR: Must pass the new branch name." 1>&2
exit 1
fi

git checkout "$1"
git checkout -b "$2"
git branch -D "$1"
git logra
3 changes: 3 additions & 0 deletions bin/git-parent-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Detect the base or parent remote branch (best guess)
git log --pretty=format:'%d' --abbrev-commit --decorate-refs-exclude=refs/tags | grep origin | head -2 | tail -1 | sed '1s/tag:[^,]*, //g' | sed -nr '1s/.*\(([^,]+),?.*/\1/p' | cut -d ')' -f 1 | cut -d '(' -f 1
17 changes: 17 additions & 0 deletions bin/git-remove-temp-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Removes a branch specified as temp of another
if [ "$1" == "" ]; then
echo -e "ERROR: Must pass branch name." 1>&2
exit 1
fi

if [ "$2" == "" ]; then
echo -e "ERROR: Must specify a temp branch name." 1>&2
exit 1
fi

git checkout "$2"
git branch -D "$1"
git checkout -b "$1"
git branch -D "$2"
git logra
89 changes: 89 additions & 0 deletions bin/git-update-parent-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# Updates the base or parent branch
CURRENT_BRANCH="$(git current-branch)"
PARENT_BRANCH=""
COMMIT_MODE="multi-commit"
UNTIL_COMMIT=""
COMMITS=""

while getopts ":-:" opt; do
case ${opt} in
-)
case ${OPTARG} in
"single-commit"*) COMMIT_MODE="single-commit";;
esac
esac
done

if [ "$COMMIT_MODE" == "single-commit" ]; then
if [ "$2" == "" ]; then
PARENT_BRANCH="$(git parent-branch)"
else
PARENT_BRANCH="$2"
fi
COMMITS="$(git rev-parse "$CURRENT_BRANCH")"
else
if [ "$1" == "" ]; then
PARENT_BRANCH="$(git parent-branch)"
COMMITS="$(git rev-list "$CURRENT_BRANCH"..."$PARENT_BRANCH")"
else
PARENT_BRANCH="$1"
COMMON_ANCESTOR="$(git merge-base "$CURRENT_BRANCH" "$PARENT_BRANCH")"
COMMITS="$(git rev-list "$CURRENT_BRANCH"..."$COMMON_ANCESTOR")"
fi

if [ "$2" != "" ]; then
UNTIL_COMMIT="$2"
fi
fi
# TODO - What if we don't have commits?

echo "CURRENT BRANCH -> $CURRENT_BRANCH"
echo "PARENT BRANCH -> $PARENT_BRANCH"
echo "COMMIT LIST -> $COMMITS"
echo "----"

# TODO - What if a checkout fails?
git checkout -b "$CURRENT_BRANCH-temp"
git fetch

git checkout "$PARENT_BRANCH" > /dev/null 2>&1
git branch -D "$CURRENT_BRANCH" > /dev/null 2>&1
git checkout -b "$CURRENT_BRANCH" > /dev/null 2>&1

# TODO - What if a cherry-pick fails?
if [ "$COMMIT_MODE" == "single-commit" ]; then
echo "----"
echo "Cherry Picking -> $COMMITS"
git cherry-pick "$COMMITS"
else
echo 'Multi Commit Mode Enabled!'
COMMIT_ARRAY=($COMMITS)
COMMITS_TO_CHERRY=()

if [ "$UNTIL_COMMIT" != "" ]; then
for commit_id in "${COMMIT_ARRAY[@]}"
do
if [[ "$commit_id" =~ "$UNTIL_COMMIT" ]]; then
break
fi
COMMITS_TO_CHERRY+=("$commit_id")
done
fi

size=${#COMMITS_TO_CHERRY[@]}
for (( i=size-1; i>=0; i-- )); do
echo "----"
if [[ "${COMMITS_TO_CHERRY[i]}" =~ "$UNTIL_COMMIT" ]]; then
echo "NOT Cherry Picking! -> ${COMMITS_TO_CHERRY[i]}"
else
echo "Cherry Picking -> ${COMMITS_TO_CHERRY[i]}"
git cherry-pick "${COMMITS_TO_CHERRY[i]}"
fi
done
fi

echo "----"
git push --set-upstream origin -f "$CURRENT_BRANCH"

git log --oneline --color --decorate --graph --all