Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bcde137050 | |||
| da31f19926 | |||
| 2b1fb56c4a | |||
| 4f142bf0dd | |||
| 5c76da3ebd | |||
| 0d632b15e1 |
@@ -5,15 +5,16 @@ Keep your repo fresh with one command.
|
||||
## Usage
|
||||
|
||||
```
|
||||
Usage: git fresh [-fmrF] [-sl] [remote] [root]
|
||||
Usage: git fresh [-fmrtF] [-sl] [remote] [root]
|
||||
By default, git-fresh will:
|
||||
- rebase against remote current branch
|
||||
- rebase against remote current branch
|
||||
- stash changes
|
||||
- prune remote branches
|
||||
|
||||
-f: Delete stale local and remote branches
|
||||
-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
|
||||
|
||||
-s: Apply stashed changes after run
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
usage () {
|
||||
cat << EOD
|
||||
Usage: git fresh [-fmrF] [-sl] [remote] [root]
|
||||
Usage: git fresh [-fmrtF] [-sl] [remote] [root]
|
||||
By default, git-fresh will:
|
||||
- rebase against remote current branch
|
||||
- stash changes
|
||||
@@ -16,6 +16,7 @@ By default, git-fresh will:
|
||||
-f: Delete stale local and remote branches
|
||||
-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
|
||||
|
||||
-s: Apply stashed changes after run
|
||||
@@ -43,7 +44,7 @@ error () {
|
||||
|
||||
trap 'error $LINENO' ERR
|
||||
|
||||
while getopts ":fmrslF" opt; do
|
||||
while getopts ":fmrtslF" opt; do
|
||||
case $opt in
|
||||
f)
|
||||
FORCE_DELETE_STALE=true
|
||||
@@ -54,6 +55,9 @@ while getopts ":fmrslF" opt; do
|
||||
r)
|
||||
REBASE=true
|
||||
;;
|
||||
t)
|
||||
TAGS=true
|
||||
;;
|
||||
s)
|
||||
APPLY_STASH=true
|
||||
;;
|
||||
@@ -136,7 +140,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 git branch -d 2> /dev/null
|
||||
echo -n $LOCAL_STALE | xargs -0 git branch -d 2> /dev/null
|
||||
else
|
||||
say "Local stale branches found:" $(echo -n $LOCAL_STALE | tr "\n" " ")
|
||||
fi
|
||||
@@ -146,7 +150,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 git push $REMOTE --delete
|
||||
echo -n $REMOTE_STALE | xargs -0 git push $REMOTE --delete
|
||||
fi
|
||||
else
|
||||
say "Remote stale branches found:" $(echo -n $REMOTE_STALE | tr "\n" " ")
|
||||
@@ -158,6 +162,8 @@ if [[ ! -z "${SMART_STALE// }" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Rebase or merge remote root against local branch
|
||||
|
||||
if [[ ! -z $(git rev-parse --verify --quiet "$CURRENT") ]]; then
|
||||
git checkout $CURRENT 2> /dev/null
|
||||
|
||||
@@ -176,6 +182,22 @@ else
|
||||
echo "$CURRENT branch was stale, staying on $ROOT"
|
||||
fi
|
||||
|
||||
# Remove local tags that are missing on the remote
|
||||
|
||||
if [[ "$TAGS" = true ]]; then
|
||||
REMOTE_TAGS=$(git ls-remote --tags $REMOTE | cut -f 2)
|
||||
LOCAL_TAGS=$(git show-ref --tags | cut -d' ' -f 2)
|
||||
|
||||
for tag in $LOCAL_TAGS; do
|
||||
if [[ -z $(grep $tag <<< "$REMOTE_TAGS" | cat) ]]; then
|
||||
MISSING_TAG="${tag//refs\/tags\/}"
|
||||
git tag -d $MISSING_TAG
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Restore stashed changes
|
||||
|
||||
if [[ ! -z $(git stash list | grep $STASH_STAMP | cat) ]]; then
|
||||
if [[ "$APPLY_STASH" = true ]]; then
|
||||
git stash pop
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "git-fresh",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.0",
|
||||
"description": "Utility to keep Git repositories fresh",
|
||||
"global": true,
|
||||
"repo": "imsky/git-fresh",
|
||||
|
||||
Reference in New Issue
Block a user