Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b191ec2f9 | |||
| 562a4b94ca | |||
| 799199dcc2 | |||
| 33df53a989 | |||
| ad4a370334 | |||
| 58851c4c15 | |||
| d33bde493a | |||
| 9a061ce30b | |||
| 236f95ea18 |
@@ -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
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
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
|
||||
- rebase against remote current branch
|
||||
- stash changes
|
||||
- prune remote branches
|
||||
|
||||
@@ -17,11 +17,14 @@ 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
|
||||
|
||||
-v: Print git-fresh version and exit
|
||||
|
||||
remote: remote name, origin by default
|
||||
root: root branch, master by default
|
||||
EOD
|
||||
@@ -44,7 +47,7 @@ error () {
|
||||
|
||||
trap 'error $LINENO' ERR
|
||||
|
||||
while getopts ":fmrtslFT" opt; do
|
||||
while getopts ":fmrtslRWTv" opt; do
|
||||
case $opt in
|
||||
f)
|
||||
FORCE_DELETE_STALE=true
|
||||
@@ -64,12 +67,18 @@ while getopts ":fmrtslFT" opt; do
|
||||
l)
|
||||
DELETE_ONLY_LOCAL=true
|
||||
;;
|
||||
F)
|
||||
FORCE_LOCAL_RESET=true
|
||||
R)
|
||||
RESET_ROOT=true
|
||||
;;
|
||||
W)
|
||||
WIPE_WORKSPACE=true
|
||||
;;
|
||||
T)
|
||||
TEST=true
|
||||
;;
|
||||
v)
|
||||
VERSION=1.8.0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
break
|
||||
@@ -79,18 +88,35 @@ done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
# Are we in version mode?
|
||||
|
||||
if [[ ! -z $VERSION ]]; then
|
||||
echo git-fresh $VERSION
|
||||
exit 0
|
||||
|
||||
fi
|
||||
|
||||
# Are we in testing mode?
|
||||
|
||||
if [[ $TEST = true ]]; then
|
||||
|
||||
PATH=$(pwd):$PATH
|
||||
TEST_DIR=/tmp/git-fresh-test
|
||||
fail_test () {
|
||||
echo 'Tests failed!'
|
||||
rm -rf $TEST_DIR
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p $TEST_DIR; cd $TEST_DIR
|
||||
rm -rf $TEST_DIR; 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
|
||||
git-fresh -fr; git rev-parse --verify test && fail_test || true
|
||||
git checkout -b test; git checkout master; git-fresh; git checkout -
|
||||
git rev-parse --abbrev-ref HEAD | grep -q test || fail_test
|
||||
rm -rf $TEST_DIR
|
||||
echo 'Tests passed!'
|
||||
exit 0
|
||||
|
||||
fi
|
||||
@@ -131,7 +157,6 @@ if [[ $REMOTES = true ]]; then
|
||||
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)
|
||||
@@ -142,19 +167,28 @@ if [[ $REMOTES = true ]]; then
|
||||
|
||||
fi
|
||||
|
||||
# Switch to root branch (master)
|
||||
# If we are not already on root branch, switch to root branch (master)
|
||||
|
||||
git checkout $ROOT > /dev/null 2>&1
|
||||
if [[ "$ROOT" != "$CURRENT" ]]; then
|
||||
git checkout $ROOT > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Wipe workspace?
|
||||
|
||||
if [[ $WIPE_WORKSPACE = true ]]; then
|
||||
git clean -dfx
|
||||
fi
|
||||
|
||||
# Reset root?
|
||||
|
||||
if [[ $REMOTES = true ]]; then
|
||||
|
||||
if [[ "$FORCE_LOCAL_RESET" = true ]]; then
|
||||
git clean -dfx
|
||||
git reset --hard $REMOTE $ROOT
|
||||
else
|
||||
git rebase -q $REMOTE $ROOT
|
||||
if [[ $RESET_ROOT = true ]]; then
|
||||
git reset --hard $REMOTE/$ROOT
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $REMOTES = true ]]; then
|
||||
git rebase -q $REMOTE/$ROOT
|
||||
fi
|
||||
|
||||
# Compute stale branches
|
||||
@@ -196,18 +230,20 @@ fi
|
||||
# Rebase or merge remote root against local branch
|
||||
|
||||
if [[ ! -z $(git rev-parse --verify --quiet "$CURRENT") ]]; then
|
||||
git checkout $CURRENT 2> /dev/null
|
||||
if [[ "$ROOT" != "$CURRENT" ]]; then
|
||||
git checkout $CURRENT
|
||||
fi
|
||||
|
||||
if [ "$REBASE" = true ] && [ "$MERGE" = true ]; then
|
||||
say "Rebase and merge enabled, skipping both"
|
||||
else
|
||||
if [[ "$REMOTES" = true ]]; then
|
||||
if [[ "$REBASE" = true ]]; then
|
||||
git rebase $REMOTE $ROOT
|
||||
git rebase $ROOT
|
||||
fi
|
||||
|
||||
if [[ "$MERGE" = true ]]; then
|
||||
git merge --no-edit $REMOTE $ROOT
|
||||
git merge --no-edit $ROOT
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "git-fresh",
|
||||
"version": "1.6.1",
|
||||
"version": "1.8.0",
|
||||
"description": "Utility to keep Git repositories fresh",
|
||||
"global": true,
|
||||
"repo": "imsky/git-fresh",
|
||||
|
||||
Reference in New Issue
Block a user