Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8974b650ac | |||
| e5ac597258 | |||
| 9999e54375 | |||
| 30657dcd75 |
@@ -7,10 +7,12 @@ Keep your repo fresh with one command.
|
||||
```
|
||||
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
|
||||
|
||||
git-fresh will ignore any branches listed in a .freshignore file.
|
||||
|
||||
-f: Delete stale local and remote branches
|
||||
-m: Merge remote root into current branch
|
||||
-r: Rebase current branch against remote root
|
||||
@@ -21,6 +23,8 @@ 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
|
||||
```
|
||||
|
||||
@@ -13,6 +13,8 @@ By default, git-fresh will:
|
||||
- stash changes
|
||||
- prune remote branches
|
||||
|
||||
git-fresh will ignore any branches listed in a .freshignore file.
|
||||
|
||||
-f: Delete stale local and remote branches
|
||||
-m: Merge remote root into current branch
|
||||
-r: Rebase current branch against remote root
|
||||
@@ -77,7 +79,7 @@ while getopts ":fmrtslRWTv" opt; do
|
||||
TEST=true
|
||||
;;
|
||||
v)
|
||||
VERSION=1.8.0
|
||||
VERSION=1.8.2
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
@@ -132,17 +134,34 @@ 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
|
||||
if [[ ! -z $(grep -Fx "$CURRENT" "$FRESH_IGNORE") ]]; then
|
||||
die "Branch $CURRENT is ignored"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
STASH_STAMP=git-fresh-$(date +%s)
|
||||
|
||||
# Stash changed files
|
||||
@@ -204,21 +223,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 +262,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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "git-fresh",
|
||||
"version": "1.8.0",
|
||||
"version": "1.9.0",
|
||||
"description": "Utility to keep Git repositories fresh",
|
||||
"global": true,
|
||||
"repo": "imsky/git-fresh",
|
||||
|
||||
Reference in New Issue
Block a user