Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32e798c218 | |||
| f18a2dc6ba | |||
| 97c7dfb4b5 | |||
| 46a74c1b08 | |||
| b9336549c1 | |||
| 30ee8139f7 | |||
| 4482885845 | |||
| 615988dc01 | |||
| c9b1f5c2e0 | |||
| 85ee0683eb | |||
| c48f1d592a | |||
| 15e62530d9 | |||
| 8e81d7276e | |||
| b6d35128c4 | |||
| 6dc3f6870d | |||
| 28f347b89d | |||
| a94af51b11 | |||
| b11805e886 | |||
| 5327cb53c9 | |||
| c5db0306de | |||
| a16bc0b0c8 |
@@ -2,23 +2,23 @@
|
||||
|
||||
Keep your repo fresh with one command.
|
||||
|
||||
* Stashes your unstaged changes
|
||||
* Updates local master to match remote, prunes stale branches
|
||||
* Deletes stale local and remote branches with `-f` flag
|
||||
* Merges remote master into current branch with `-m` flag
|
||||
* Rebases current branch against remote master with `-r` flag
|
||||
* Restores your stashed changes with `-s` flag
|
||||
* Wipes the slate clean with `-F` flag
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
Usage: git fresh [-fmrsF] [remote] [root]
|
||||
Usage: git fresh [-fmrF] [-sl] [remote] [root]
|
||||
By default, git-fresh will:
|
||||
- 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
|
||||
-s: Apply stashed changes after run
|
||||
-F: Reset local root to remote root, wipe workspace
|
||||
|
||||
-s: Apply stashed changes after run
|
||||
-l: Only delete local stale branches
|
||||
|
||||
remote: remote name, origin by default
|
||||
root: root branch, master by default
|
||||
```
|
||||
@@ -29,7 +29,7 @@ root: root branch, master by default
|
||||
|
||||
1. Clone or download
|
||||
2. `cd git-fresh`
|
||||
3. `sudo make install`
|
||||
3. `sudo ./install`
|
||||
|
||||
### Package
|
||||
|
||||
|
||||
@@ -1,24 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# git-fresh
|
||||
# https://github.com/imsky/git-fresh
|
||||
# By Ivan Malopinsky - http://imsky.co
|
||||
# MIT License
|
||||
|
||||
usage () {
|
||||
echo "Usage: git fresh [-fmrsF] [remote] [root]"
|
||||
echo "-f: Delete stale local and remote branches"
|
||||
echo "-m: Merge remote root into current branch"
|
||||
echo "-r: Rebase current branch against remote root"
|
||||
echo "-s: Apply stashed changes after run"
|
||||
echo "-F: Reset local root to remote root, wipe workspace"
|
||||
echo "remote: remote name, origin by default"
|
||||
echo "root: root branch, master by default"
|
||||
exit 1;
|
||||
cat << EOD
|
||||
Usage: git fresh [-fmrF] [-sl] [remote] [root]
|
||||
By default, git-fresh will:
|
||||
- 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
|
||||
-F: Reset local root to remote root, wipe workspace
|
||||
|
||||
-s: Apply stashed changes after run
|
||||
-l: Only delete local stale branches
|
||||
|
||||
remote: remote name, origin by default
|
||||
root: root branch, master by default
|
||||
EOD
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
error () {
|
||||
echo -n "[git-fresh] error on line $1"
|
||||
echo "[git-fresh] error on line $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
die () {
|
||||
echo "[git-fresh] $@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trap 'error $LINENO' ERR
|
||||
|
||||
while getopts "fmrsF" opt; do
|
||||
while getopts ":fmrslF" opt; do
|
||||
case $opt in
|
||||
f)
|
||||
FORCE_DELETE_STALE=true
|
||||
@@ -32,17 +54,24 @@ while getopts "fmrsF" opt; do
|
||||
s)
|
||||
APPLY_STASH=true
|
||||
;;
|
||||
l)
|
||||
DELETE_ONLY_LOCAL=true
|
||||
;;
|
||||
F)
|
||||
FORCE_LOCAL_RESET=true
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
[[ ! -e .git ]] && die "Not a git repository"
|
||||
[[ $(ls -l .git/refs/heads | wc -l) -eq "1" ]] && die "No HEAD ref available"
|
||||
|
||||
CURRENT=$(git rev-parse --abbrev-ref HEAD)
|
||||
REMOTE=${1:-origin}
|
||||
ROOT=${2:-master}
|
||||
@@ -56,6 +85,8 @@ if ! git diff-files --quiet; then
|
||||
git stash save $STASH_STAMP
|
||||
fi
|
||||
|
||||
git rebase $REMOTE $CURRENT
|
||||
|
||||
git checkout $ROOT > /dev/null 2>&1
|
||||
|
||||
if [[ "$FORCE_LOCAL_RESET" = true ]]; then
|
||||
@@ -86,13 +117,15 @@ if [[ ! -z "${SMART_STALE// }" ]]; then
|
||||
if [[ ! -z "${REMOTE_STALE// }" ]]; then
|
||||
STALE_BRANCHES=true
|
||||
if [[ "$FORCE_DELETE_STALE" = true ]]; then
|
||||
echo -n $REMOTE_STALE | xargs git push $REMOTE --delete
|
||||
if [[ "$DELETE_ONLY_LOCAL" != true ]]; then
|
||||
echo -n $REMOTE_STALE | xargs git push $REMOTE --delete
|
||||
fi
|
||||
else
|
||||
echo "Remote stale branches found:" $(echo -n $REMOTE_STALE | tr "\n" " ")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$FORCE_DELETE_STALE" != true && $STALE_BRANCHES = true ]]; then
|
||||
if [[ "$FORCE_DELETE_STALE" != true && "$STALE_BRANCHES" = true ]]; then
|
||||
echo "Delete stale branches with: git fresh -f"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
INSTALL_DIR=${1:-/usr/local/bin}
|
||||
|
||||
mkdir -p $INSTALL_DIR
|
||||
cp git-fresh $INSTALL_DIR && ([ -e $INSTALL_DIR/git-fresh ] && echo git-fresh installed in $INSTALL_DIR)
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "git-fresh",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.0",
|
||||
"description": "Utility to keep Git repositories fresh",
|
||||
"global": true,
|
||||
"repo": "imsky/git-fresh",
|
||||
"install": "sudo make install"
|
||||
"install": "sudo ./install"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user