Skip to content

Commit

Permalink
git-bubbles
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitfred committed Sep 3, 2014
1 parent f830004 commit 3173ec6
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
78 changes: 78 additions & 0 deletions git-bubbles
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -e

function log {
git --no-pager log --oneline --decorate --graph "$@"
}

filter_pattern=$(git config bubbles.pattern || echo "--")
mine=$(git config bubbles.remote-name || echo "origin")

commit=$(git find-pushable-head "$filter_pattern")
branch_name=$(git rev-parse --symbolic-full-name HEAD | sed 's-^refs/heads/--')

push_command="git push $mine $commit:$branch_name --force"

function print_log {
if [[ ! $(git rev-parse HEAD) =~ ^$commit ]]; then
log "${commit}..HEAD"
echo "--------------------------------------------------"
fi
log "HEAD@{u}..$commit"
}

function announce {
echo "$*"
"$@"
}

function print_status {
local command=$1
missing_branch=$(git rev-parse "$mine/$branch_name" >/dev/null 2>/dev/null || echo "1")

if [ "$missing_branch" == "1" ]; then
echo "Branch $branch_name not yet pushed on ${mine}. To create it:"
echo "git push $mine HEAD"
else
diff_stat=$(git diff --stat "$mine/$branch_name..$commit" 2>/dev/null | wc -c)
log_stat=$(git --no-pager log --oneline "$mine/$branch_name..$commit" 2>/dev/null | wc -l)
if [ "$diff_stat" != "0" ]; then
if [ "$command" == "execute" ]; then
$push_command
else
announce git diff -b -M "$mine/$branch_name..$commit" --stat

echo ""
echo "$push_command"
fi
elif [ "$log_stat" != "0" ]; then
echo "No diff but history diverged."
echo ""
if [ "$command" == "execute" ]; then
$push_command
else
echo "$push_command"
fi
else
echo "Nothing to push. We're good!"
fi
fi
}

if [ "$1" == "push" ]; then
print_status execute

elif [ "$1" == "diff" ]; then
shift 1
if [ "$diff_stat" != "0" ]; then
announce git diff -b -M "$mine/$branch_name..$commit" "$@"
fi

elif [ "$1" == "content" ]; then
shift 1
git diff --stat --patch -w -M "HEAD@{u}..$commit" "$@"

else
print_log
echo ""
print_status
fi
4 changes: 4 additions & 0 deletions git-find-pushable-head
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

pattern=$1
git log --oneline "HEAD@{u}.." | sed "/${pattern}/d" | head -1 | cut -d" " -f1

0 comments on commit 3173ec6

Please sign in to comment.