Merge branch 'master' of https://github.com/wmhilton/gitredux
This commit is contained in:
commit
6863e8eb98
2 changed files with 100 additions and 19 deletions
17
README.md
17
README.md
|
|
@ -1,9 +1,6 @@
|
|||
# gitredux
|
||||
###This project is nascent and in a state of flux!
|
||||
|
||||
I started this project because `git log --no-pager` gives an error. Apparently I wanted `git --no-pager log`. This was the last straw.
|
||||
*So I decided to "fix" the git CLI.*
|
||||
|
||||
This project takes inspiration from [gitless](http://gitless.com/) and [legit](https://github.com/kennethreitz/legit), and is
|
||||
influenced by this [blog post](http://www.saintsjd.com/2012/01/a-better-ui-for-git/) and this [fantastic diatribe](http://stevebennett.me/2012/02/24/10-things-i-hate-about-git).
|
||||
However, I feel all of these tools are either underdeveloped or too opinionated. I want a tool that gives me all the
|
||||
|
|
@ -14,6 +11,18 @@ same control as git but without the headache of its impossible to remember comma
|
|||
* Fewer, more orthogonal commands
|
||||
* More useful (and non-destructive) default behaviors
|
||||
|
||||
### Why?
|
||||
I started this project because `git log --no-pager` gives an error. Apparently I wanted `git --no-pager log`. This was the last straw.
|
||||
*So I decided to "fix" the git CLI.*
|
||||
|
||||
EDIT: Even better example of inanity of git CLI: To get the SHA reference of HEAD, do you use `git show-ref HEAD --abbrev --hash` or `git rev-parse --short HEAD`?
|
||||
|
||||
* Why are they different results?
|
||||
* Why does `show-ref` use `--abbrev` but `rev-parse` use `--short`?
|
||||
* Why are the options _after_ `HEAD` in `show-ref` but _before_ `HEAD` in `rev-parse`?
|
||||
* I leave answering these questions as an exercise to the reader.
|
||||
|
||||
|
||||
### Commands
|
||||
(bound to get out of date quickly)
|
||||
|
||||
|
|
@ -40,6 +49,8 @@ get diff %REFA% %REFB% | compare %REFA% with %REFB% (git diff %REFA% %REFB%)
|
|||
get undo commit | git reset --soft HEAD~1
|
||||
get push | pushes to upstream. If upstream not set, prompt user to name a remote branch. (If multiple remotes exist, prompt for which remote to use.)
|
||||
get clone %PATH% | %PATH% can be a normal url. Paths like "username/repo" will be expanded assuming a Github. Paths with just "repo" will expand to a Github url, if your Github username is stored in git config.
|
||||
get tag %TAG% | git tag %TAG%
|
||||
get untag %TAG% | Deletes local tag. Y/N prompt to delete remote tag.
|
||||
|
||||
### TODO
|
||||
Now that I've added tab completion, I think "stage" and "status" are too similar.
|
||||
|
|
|
|||
102
bin/get
102
bin/get
|
|
@ -10,8 +10,17 @@ list_remote_branches() {
|
|||
}
|
||||
|
||||
case "$1" in
|
||||
"")
|
||||
echo 'TODO: Display help, or git status if inside a repo'
|
||||
"" | status)
|
||||
# TODO: Display help if not inside a repo
|
||||
# TODO: figure out how to git config --global color.status always automatically.
|
||||
git status \
|
||||
| grep -v 'On branch' \
|
||||
| grep -v '(use "git push" to publish your local commits)' \
|
||||
| grep -v '(use "git reset HEAD <file>..." to unstage)' \
|
||||
| grep -v '(use "git add <file>..." to update what will be committed)' \
|
||||
| grep -v '(use "git checkout -- <file>..." to discard changes in working directory)' \
|
||||
| grep -v '(use "git add <file>..." to include in what will be committed)' \
|
||||
| grep -v 'nothing added to commit but untracked files present (use "git add" to track)'
|
||||
;;
|
||||
|
||||
stage)
|
||||
|
|
@ -34,6 +43,48 @@ else
|
|||
fi
|
||||
;;
|
||||
|
||||
tag)
|
||||
echo Tagging
|
||||
git tag "$2"
|
||||
;;
|
||||
|
||||
untag)
|
||||
# Delete tag (if tag exists)
|
||||
if git rev-parse "$2" >/dev/null 2>&1
|
||||
then
|
||||
echo Deleting tag "$2"
|
||||
git tag -d "$2"
|
||||
fi
|
||||
# Get local branch name
|
||||
local_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
# Get associated remote
|
||||
remote=$(git config --get branch.$local_branch.remote)
|
||||
# If tag is not present on remote, stop here.
|
||||
exist=$(git ls-remote --tags "$remote" "$2")
|
||||
if [ "$exist" != '' ]
|
||||
then
|
||||
# Prompt user to delete on upstream.
|
||||
read -e -p "Would you like to delete the tag on remote '${remote}'? [Y/n]: " deltag
|
||||
deltag=${deltag:-Y}
|
||||
case "$deltag" in
|
||||
[Yy] | [Yy][Ee][Ss] )
|
||||
git push --delete "$remote" "$2"
|
||||
;;
|
||||
[Nn] | [Nn][Oo] )
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
|
||||
add)
|
||||
# TODO: make add only add untracked files (useful when auto-completing)
|
||||
;;
|
||||
|
||||
rm)
|
||||
echo Removing
|
||||
git rm "$2"
|
||||
;;
|
||||
|
||||
reset)
|
||||
echo Resetting
|
||||
if [ -z "$2" ]; then
|
||||
|
|
@ -68,13 +119,13 @@ echo 'Switching to branch'
|
|||
if [ -z "$2" ]; then
|
||||
echo '! Specify branch name'
|
||||
else
|
||||
git stash # Save branch index state
|
||||
git stash save --include-untracked --quiet 'get-branch autostash' # Save branch index state
|
||||
if git rev-parse --verify --quiet "$2" > /dev/null; then
|
||||
git checkout "$2"
|
||||
else
|
||||
git checkout -b "$2"
|
||||
fi
|
||||
git stash pop # Restore branch index state
|
||||
git stash pop --quiet # Restore branch index state
|
||||
fi
|
||||
;;
|
||||
|
||||
|
|
@ -114,18 +165,6 @@ ignore)
|
|||
|
||||
;;
|
||||
|
||||
status)
|
||||
# TODO: figure out how to git config --global color.status always automatically.
|
||||
git status \
|
||||
| grep -v 'On branch' \
|
||||
| grep -v '(use "git push" to publish your local commits)' \
|
||||
| grep -v '(use "git reset HEAD <file>..." to unstage)' \
|
||||
| grep -v '(use "git add <file>..." to update what will be committed)' \
|
||||
| grep -v '(use "git checkout -- <file>..." to discard changes in working directory)' \
|
||||
| grep -v '(use "git add <file>..." to include in what will be committed)' \
|
||||
| grep -v 'nothing added to commit but untracked files present (use "git add" to track)'
|
||||
;;
|
||||
|
||||
diff)
|
||||
# Note: we use --ignore-space-change with every diff because
|
||||
# changing the amount of indentation of large chunks of code
|
||||
|
|
@ -204,4 +243,35 @@ echo Cloning $url
|
|||
git clone "$url"
|
||||
;;
|
||||
|
||||
squash)
|
||||
# I implement squash a little differently than most.
|
||||
# 1) Rebase squashing aggregates commit messages, which is usually
|
||||
# counter to the purpose of squashing, which is to hide the fact
|
||||
# that a change took several real commits.
|
||||
# 2) Rebasing also deletes commits by default, which is problematic
|
||||
# if you have pushed those commits to the server already.
|
||||
# This solution is more gentle in that it creates a new commit with
|
||||
# a new commit message containing the same changes as the old
|
||||
# series of commits, but doesn't delete the old commits, leaving them
|
||||
# as a branch.
|
||||
# TODO: check argument is numeric
|
||||
if [[ "$2" =~ ^[0-9]+$ ]]
|
||||
then
|
||||
echo "Squash the following commits together:"
|
||||
git log --abbrev-commit \
|
||||
--color \
|
||||
--graph \
|
||||
--ancestry-path \
|
||||
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
|
||||
HEAD...HEAD~$2
|
||||
read -p 'Message: ' msg
|
||||
git stash save --include-untracked --quiet 'get-squash autostash'
|
||||
git reset --soft HEAD~$(($2+1))
|
||||
git commit -m "$msg"
|
||||
git stash pop --quiet
|
||||
else
|
||||
echo "The second argument is expected to be an integer."
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue