14 Commits

Author SHA1 Message Date
Ivan Malopinsky c6fcd81155 Merge pull request #84 from koppor/patch-1
Add installation hints for Windows
2017-12-08 09:07:07 -05:00
Oliver Kopp 5b99160266 Add installation hints for Windows 2017-12-08 09:11:52 +01:00
Ivan Malopinsky 38e71f6f9d update git-fresh docs 2017-11-14 23:06:46 -05:00
Ivan Malopinsky fa9b2a38b1 1.11.0 2017-11-14 23:04:37 -05:00
Ivan Malopinsky d3f7a39b96 do not rebase local current branch against remote branch. ff-merge instead of rebasing local root 2017-11-14 23:03:43 -05:00
Ivan Malopinsky bc874fa5bd run git prune if git gc fails
resolve #83
2017-11-14 22:51:48 -05:00
Ivan Malopinsky f0c9f902a4 1.10.1 2017-07-19 20:07:55 -04:00
Ivan Malopinsky b9e145abdf Create LICENSE 2017-07-18 21:12:02 -04:00
Ivan Malopinsky a129ad766a git remote prune before remote update, resolve #79 #80 2017-07-18 21:09:27 -04:00
Ivan Malopinsky 8f4a8a326e support a global .freshignore, fix #76 2017-07-18 20:50:55 -04:00
Ivan Malopinsky 8974b650ac recover HEAD ref, fix #77 2017-04-25 22:49:30 -04:00
Ivan Malopinsky e5ac597258 .freshignore support for local and remote branch cleanup 2016-09-30 22:13:52 -04:00
Ivan Malopinsky 9999e54375 start on branch ignore support 2016-09-25 22:55:09 -04:00
Ivan Malopinsky 30657dcd75 clean tracking information for missing upstreams
fix #63
2016-09-24 22:55:09 -04:00
4 changed files with 122 additions and 50 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Ivan Malopinsky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+15 -3
View File
@@ -1,4 +1,4 @@
# git-fresh :lemon:
# git-fresh :lemon:
Keep your repo fresh with one command.
@@ -7,10 +7,15 @@ Keep your repo fresh with one command.
```
Usage: git fresh [-fmrtRW] [-sl] [remote] [root]
By default, git-fresh will:
- rebase against remote current branch
- update local root (master) to match remote root
- stash changes
- prune remote branches
git-fresh will ignore any branches listed in a .freshignore file.
.freshignore should contain branch names you would like to ignore
on separate lines. The file can exist in the current Git repo
or in the home directory, i.e. ~/.freshignore.
-f: Delete stale local and remote branches
-m: Merge remote root into current branch
-r: Rebase current branch against remote root
@@ -21,18 +26,25 @@ By default, git-fresh will:
-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
```
## Installation
### Manual
### Manual on Linux or MacOSX
1. Clone or download
2. `cd git-fresh`
3. `sudo ./install`
### Manual on Windows
Copy the file [git-fresh](https://raw.githubusercontent.com/imsky/git-fresh/master/git-fresh) to `usr\bin` in your git installation directory.
This usually is `C:\Program Files\Git\usr\bin`.
### Package
* [Homebrew](http://brew.sh/): `brew install git-fresh`
+85 -46
View File
@@ -9,10 +9,15 @@ usage () {
cat << EOD
Usage: git fresh [-fmrtRW] [-sl] [remote] [root]
By default, git-fresh will:
- rebase against remote current branch
- update local root (master) to match remote root
- stash changes
- prune remote branches
git-fresh will ignore any branches listed in a .freshignore file.
.freshignore should contain branch names you would like to ignore
on separate lines. The file can exist in the current Git repo
or in the home directory, i.e. ~/.freshignore.
-f: Delete stale local and remote branches
-m: Merge remote root into current branch
-r: Rebase current branch against remote root
@@ -77,7 +82,7 @@ while getopts ":fmrtslRWTv" opt; do
TEST=true
;;
v)
VERSION=1.8.0
VERSION=1.11.0
;;
*)
usage
@@ -91,34 +96,31 @@ shift $((OPTIND-1))
# Are we in version mode?
if [[ ! -z $VERSION ]]; then
echo git-fresh $VERSION
exit 0
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
}
PATH=$(pwd):$PATH
TEST_DIR=/tmp/git-fresh-test
fail_test () {
echo 'Tests failed!'
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; 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
exit 1
}
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; 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
echo 'Tests passed!'
exit 0
fi
# Are we inside a git repository?
@@ -132,17 +134,38 @@ fi
# Are we in a non-empty git repository?
TOP_LEVEL_DIRECTORY=$(git rev-parse --show-toplevel)
[[ $(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}
if [[ $(ls -1 "$TOP_LEVEL_DIRECTORY/.git/refs/heads" | wc -l | xargs) -eq "0" ]]; then
if git rev-parse --verify "$ROOT"; then
git rev-parse "$ROOT" > "$TOP_LEVEL_DIRECTORY/.git/refs/heads/$ROOT"
else
(git fsck --lost-found &> /dev/null; git checkout "$ROOT") || die "No HEAD ref available"
fi
fi
CURRENT=$(git rev-parse --abbrev-ref HEAD)
if [[ $(git remote -v | wc -l) -gt "0" ]]; then
REMOTES=true
fi
# Is this branch in .freshignore?
FRESH_IGNORE="$TOP_LEVEL_DIRECTORY/.freshignore"
if [[ ! -f $FRESH_IGNORE ]]; then
FRESH_IGNORE="~/.freshignore"
fi
if [[ -f $FRESH_IGNORE ]]; then
if [[ ! -z $(grep -Fx "$CURRENT" "$FRESH_IGNORE") ]]; then
die "Branch $CURRENT is ignored"
fi
fi
STASH_STAMP=git-fresh-$(date +%s)
# Stash changed files
@@ -152,19 +175,11 @@ if ! git diff-files --quiet; then
fi
if [[ $REMOTES = true ]]; then
# 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
git remote prune $REMOTE
git remote update $REMOTE
git remote prune $REMOTE
fi
# If we are not already on root branch, switch to root branch (master)
@@ -179,16 +194,15 @@ if [[ $WIPE_WORKSPACE = true ]]; then
git clean -dfx
fi
# Reset root?
if [[ $REMOTES = true ]]; then
# Reset root?
if [[ $RESET_ROOT = true ]]; then
git reset --hard $REMOTE/$ROOT
fi
fi
if [[ $REMOTES = true ]]; then
git rebase -q $REMOTE/$ROOT
git pull --quiet --ff-only $REMOTE $ROOT || say "Fast forward merge failed on $ROOT. You can reset local $ROOT by running git fresh -R."
fi
# Compute stale branches
@@ -204,21 +218,37 @@ REMOTE_STALE=${REMOTE_STALE//remotes\/$REMOTE\/}
if [[ ! -z "${SMART_STALE// }" ]]; then
if [[ ! -z "${LOCAL_STALE// }" ]]; then
STALE_BRANCHES=true
if [[ -f "$FRESH_IGNORE" ]]; then
LOCAL_STALE=$(echo -n $LOCAL_STALE | tr " " "\n" | grep -Fxvf "$FRESH_IGNORE" | tr "\n" " ")
if [[ -z $LOCAL_STALE ]]; then
STALE_BRANCHES=false
fi
fi
if [[ "$FORCE_DELETE_STALE" = true ]]; then
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" " ")
if [[ $STALE_BRANCHES = true ]]; then
say "Local stale branches found:" $(echo -n $LOCAL_STALE | tr "\n" " ")
fi
fi
fi
if [[ ! -z "${REMOTE_STALE// }" ]]; then
STALE_BRANCHES=true
if [[ -f "$FRESH_IGNORE" ]]; then
REMOTE_STALE=$(echo -n $REMOTE_STALE | tr " " "\n" | grep -Fxvf "$FRESH_IGNORE" | tr "\n" " ")
if [[ -z $REMOTE_STALE ]]; then
STALE_BRANCHES=false
fi
fi
if [[ "$FORCE_DELETE_STALE" = true ]]; then
if [[ "$DELETE_ONLY_LOCAL" != true ]]; then
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" " ")
if [[ $STALE_BRANCHES = true ]]; then
say "Remote stale branches found:" $(echo -n $REMOTE_STALE | tr "\n" " ")
fi
fi
fi
@@ -227,6 +257,12 @@ if [[ ! -z "${SMART_STALE// }" ]]; then
fi
fi
# Remove tracking information for missing upstreams
if [[ ! -z $(git branch -vv | grep -F "[$REMOTE/$CURRENT: gone]") ]]; then
git branch --unset-upstream $CURRENT
fi
# Rebase or merge remote root against local branch
if [[ ! -z $(git rev-parse --verify --quiet "$CURRENT") ]]; then
@@ -275,4 +311,7 @@ if [[ ! -z $(git stash list | grep $STASH_STAMP | cat) ]]; then
fi
fi
git gc --auto --prune=now
if ! git gc --auto --force; then
git prune
rm -rf "$TOP_LEVEL_DIRECTORY/.git/gc.log"
fi
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "git-fresh",
"version": "1.8.0",
"version": "1.11.0",
"description": "Utility to keep Git repositories fresh",
"global": true,
"repo": "imsky/git-fresh",