12 Commits

Author SHA1 Message Date
Ivan Malopinsky 33df53a989 bump version to 1.7.0 2016-05-14 00:00:00 -04:00
Ivan Malopinsky ad4a370334 update docs with -R and -W 2016-05-13 00:00:00 -04:00
Ivan Malopinsky 58851c4c15 add -W and -R to split -F 2016-05-12 00:00:00 -04:00
Ivan Malopinsky d33bde493a bump to 1.6.2 2016-03-30 12:23:19 -04:00
Ivan Malopinsky 9a061ce30b reset/rebase against remote branches 2016-03-29 11:05:34 -04:00
Ivan Malopinsky 236f95ea18 merge/rebase against local root
fix #68
2016-03-28 17:34:47 -04:00
Ivan Malopinsky 2da11516b4 1.6.1 2016-03-22 22:20:19 -04:00
Ivan Malopinsky e735f44727 integrated testing mode 2016-03-22 22:20:14 -04:00
Ivan Malopinsky 8f40e82492 1.6.0 2016-03-22 22:02:03 -04:00
Ivan Malopinsky da4e21fe5c add remote testing 2016-03-22 22:01:24 -04:00
Ivan Malopinsky 01a44ddc7c replace spaces with NULs for xargs -0 2016-03-09 22:45:08 -05:00
Ivan Malopinsky 0702c3a67b only run remote commands if remote is present, rework rebase/reset 2016-03-09 22:38:49 -05:00
4 changed files with 74 additions and 30 deletions
+3 -2
View File
@@ -5,7 +5,7 @@ Keep your repo fresh with one command.
## Usage
```
Usage: git fresh [-fmrtF] [-sl] [remote] [root]
Usage: git fresh [-fmrtRW] [-sl] [remote] [root]
By default, git-fresh will:
- rebase against remote current branch
- stash changes
@@ -15,7 +15,8 @@ By default, git-fresh will:
-m: Merge remote root into current branch
-r: Rebase current branch against remote root
-t: Remove local tags that do not exist on remote
-F: Reset local root to remote root, wipe workspace
-R: Reset local root to remote root
-W: Wipe workspace clean
-s: Apply stashed changes after run
-l: Only delete local stale branches
+69 -26
View File
@@ -7,7 +7,7 @@
usage () {
cat << EOD
Usage: git fresh [-fmrtF] [-sl] [remote] [root]
Usage: git fresh [-fmrtRW] [-sl] [remote] [root]
By default, git-fresh will:
- rebase against remote current branch
- stash changes
@@ -17,7 +17,8 @@ By default, git-fresh will:
-m: Merge remote root into current branch
-r: Rebase current branch against remote root
-t: Remove local tags that do not exist on remote
-F: Reset local root to remote root, wipe workspace
-R: Reset local root to remote root
-W: Wipe workspace clean
-s: Apply stashed changes after run
-l: Only delete local stale branches
@@ -39,12 +40,12 @@ die () {
}
error () {
die "error on line $1"
die "Error on line $1: $(head -n $1 $0 | tail -1)"
}
trap 'error $LINENO' ERR
while getopts ":fmrtslF" opt; do
while getopts ":fmrtslRWT" opt; do
case $opt in
f)
FORCE_DELETE_STALE=true
@@ -64,8 +65,14 @@ while getopts ":fmrtslF" opt; do
l)
DELETE_ONLY_LOCAL=true
;;
F)
FORCE_LOCAL_RESET=true
R)
RESET_ROOT=true
;;
W)
WIPE_WORKSPACE=true
;;
T)
TEST=true
;;
*)
usage
@@ -76,6 +83,22 @@ done
shift $((OPTIND-1))
# Are we in testing mode?
if [[ $TEST = true ]]; then
PATH=$(pwd):$PATH
TEST_DIR=/tmp/git-fresh-test
mkdir -p $TEST_DIR; cd $TEST_DIR
git init; touch test; git add test; git commit -am 'test'
git checkout -b test; rm test; git commit -am 'delete test'
git checkout master; git merge test; git checkout test
git-fresh -fr; rm -rf $TEST_DIR
exit 0
fi
# Are we inside a git repository?
INSIDE_GIT_REPO=$(git rev-parse --is-inside-work-tree 2> /dev/null)
@@ -88,16 +111,15 @@ fi
TOP_LEVEL_DIRECTORY=$(git rev-parse --show-toplevel)
[[ $(ls -l "$TOP_LEVEL_DIRECTORY/.git/refs/heads" | wc -l) -eq "1" ]] && die "No HEAD ref available"
[[ $(ls -1 "$TOP_LEVEL_DIRECTORY/.git/refs/heads" | wc -l | xargs) -eq "0" ]] && die "No HEAD ref available"
CURRENT=$(git rev-parse --abbrev-ref HEAD)
REMOTE=${1:-origin}
ROOT=${2:-master}
# Update remotes and prune stale remotes
git remote update
git remote prune $REMOTE
if [[ $(git remote -v | wc -l) -gt "0" ]]; then
REMOTES=true
fi
STASH_STAMP=git-fresh-$(date +%s)
@@ -107,22 +129,41 @@ if ! git diff-files --quiet; then
git stash save $STASH_STAMP
fi
# If the current branch exists on the remote, rebase against it
if [[ $REMOTES = true ]]; then
REMOTE_CURRENT=$(git ls-remote $REMOTE --heads 2> /dev/null | grep "heads/$CURRENT$" | cat)
# Update remotes and prune stale remotes
git remote update
git remote prune $REMOTE
# If the current branch exists on the remote, rebase against it
REMOTE_CURRENT=$(git ls-remote $REMOTE --heads 2> /dev/null | grep "heads/$CURRENT$" | cat)
if [[ ! -z "$REMOTE_CURRENT" ]]; then
git rebase $REMOTE $CURRENT
fi
if [[ ! -z "$REMOTE_CURRENT" ]]; then
git rebase $REMOTE $CURRENT
fi
# Switch to root branch (master)
git checkout $ROOT > /dev/null 2>&1
if [[ "$FORCE_LOCAL_RESET" = true ]]; then
# Wipe workspace?
if [[ $WIPE_WORKSPACE = true ]]; then
git clean -dfx
git reset --hard $REMOTE/$ROOT
else
fi
# Reset root?
if [[ $REMOTES = true ]]; then
if [[ $RESET_ROOT = true ]]; then
git reset --hard $REMOTE/$ROOT
fi
fi
if [[ $REMOTES = true ]]; then
git rebase -q $REMOTE/$ROOT
fi
@@ -140,7 +181,7 @@ if [[ ! -z "${SMART_STALE// }" ]]; then
if [[ ! -z "${LOCAL_STALE// }" ]]; then
STALE_BRANCHES=true
if [[ "$FORCE_DELETE_STALE" = true ]]; then
echo -n $LOCAL_STALE | xargs -0 git branch -d 2> /dev/null
echo -n $LOCAL_STALE | tr " " "\0" | xargs -0 git branch -d 2> /dev/null
else
say "Local stale branches found:" $(echo -n $LOCAL_STALE | tr "\n" " ")
fi
@@ -150,7 +191,7 @@ if [[ ! -z "${SMART_STALE// }" ]]; then
STALE_BRANCHES=true
if [[ "$FORCE_DELETE_STALE" = true ]]; then
if [[ "$DELETE_ONLY_LOCAL" != true ]]; then
echo -n $REMOTE_STALE | xargs -0 git push $REMOTE --delete
echo -n $REMOTE_STALE | tr " " "\0" | xargs -0 git push $REMOTE --delete
fi
else
say "Remote stale branches found:" $(echo -n $REMOTE_STALE | tr "\n" " ")
@@ -165,17 +206,19 @@ fi
# Rebase or merge remote root against local branch
if [[ ! -z $(git rev-parse --verify --quiet "$CURRENT") ]]; then
git checkout $CURRENT 2> /dev/null
git checkout $CURRENT
if [ "$REBASE" = true ] && [ "$MERGE" = true ]; then
say "Rebase and merge enabled, skipping both"
else
if [[ "$REBASE" = true ]]; then
git rebase $REMOTE/$ROOT
fi
if [[ "$REMOTES" = true ]]; then
if [[ "$REBASE" = true ]]; then
git rebase $ROOT
fi
if [[ "$MERGE" = true ]]; then
git merge --no-edit $REMOTE/$ROOT
if [[ "$MERGE" = true ]]; then
git merge --no-edit $ROOT
fi
fi
fi
else
View File
+2 -2
View File
@@ -1,8 +1,8 @@
{
"name": "git-fresh",
"version": "1.5.0",
"version": "1.7.0",
"description": "Utility to keep Git repositories fresh",
"global": true,
"repo": "imsky/git-fresh",
"install": "sudo ./install"
"install": "sudo ./install.sh"
}