Skip to content

Instantly share code, notes, and snippets.

@ptitfred
Created March 23, 2012 10:48
Show Gist options
  • Save ptitfred/2169524 to your computer and use it in GitHub Desktop.
Save ptitfred/2169524 to your computer and use it in GitHub Desktop.
Incremental Maven Build for Modules based Maven project
#!/bin/bash -e
# NB: the file is named git-incr-build.sh to let Gist colorize, but you should name it git-incr-build
# Put this script in your PATH and call it this way:
# git incr-build clean install
# Can be combined with git pull --rebase and git push to make an "fast & safe push" script
function branchName {
git rev-parse --symbolic-full-name --abbrev-ref $1
}
currentBranch=$(branchName HEAD)
function assertHasUpstream {
local branchName=$1
git rev-parse ${branchName}@{u} >/dev/null 2>/dev/null || (
echo Current branch \'$branchName\' has no upstream configured.
echo Set one with this:
echo git branch --set-upstream $branchName '<reference/branch>'
exit 1
)
}
assertHasUpstream $currentBranch
function dt {
local branch=$1
git diff-tree $branch@{u}..$branch
}
function rootHasBeenTouched {
# git diff-tree list files and directories modified by a commit range
# directories have a type of 04000000 and files something like 100644 (last 3 nibbles are chmod)
# so -v "040000" will discard directories and -c will count the rest
dt $1 | grep -v ":040000 040000" -c
}
function modulesTouched {
dt $1 | grep ":040000 040000" | cut -f2 | xargs | sed 's/ /,/g'
}
if [[ $(rootHasBeenTouched $currentBranch) -eq 0 ]]
then
options="--pl $(modulesTouched $currentBranch) --also-make-dependents"
fi
mvn $options $*
#!/bin/bash -e
# NB: the file is named git-safe-push.sh to let Gist colorize, but you should name it git-safe-push
# Put this script in your PATH and call it this way:
# git safe-push
# Don't forget to configure the branch to have a upstream branch
currentBranch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
git pull --rebase
git incr-build clean install
git push origin $currentBranch
@ptitfred
Copy link
Author

git safe-push script to automatize push process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment