-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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 |