From afba5f9252c943a86b83f68b73c3d48eaf0d0527 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Tue, 4 Aug 2015 16:42:34 -0400 Subject: [PATCH 1/6] Bugfix auto-stashing in 'get branch' --- bin/get | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/get b/bin/get index b4f5070..4aa5652 100755 --- a/bin/get +++ b/bin/get @@ -68,13 +68,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 ;; From fba79b889497fa47de635aba4f31f2d509d3cec1 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Tue, 4 Aug 2015 16:42:52 -0400 Subject: [PATCH 2/6] Add "get squash" command. --- bin/get | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bin/get b/bin/get index 4aa5652..e27b191 100755 --- a/bin/get +++ b/bin/get @@ -201,4 +201,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 From 04d090fee9aef6b69e8ea5a1ac5327ed2bc71a7c Mon Sep 17 00:00:00 2001 From: William Hilton Date: Thu, 6 Aug 2015 23:47:29 -0400 Subject: [PATCH 3/6] Added rm --- bin/get | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/bin/get b/bin/get index e27b191..a842b20 100755 --- a/bin/get +++ b/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 ..." to unstage)' \ +| grep -v '(use "git add ..." to update what will be committed)' \ +| grep -v '(use "git checkout -- ..." to discard changes in working directory)' \ +| grep -v '(use "git add ..." 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,15 @@ else 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 @@ -114,18 +132,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 ..." to unstage)' \ -| grep -v '(use "git add ..." to update what will be committed)' \ -| grep -v '(use "git checkout -- ..." to discard changes in working directory)' \ -| grep -v '(use "git add ..." to include in what will be committed)' \ -| grep -v 'nothing added to commit but untracked files present (use "git add" to track)' -;; - diff) if [ -z "$2" ]; then echo 'Compare working tree with HEAD' From fd17aeaf0aecf42bed25069782a5750f30eca427 Mon Sep 17 00:00:00 2001 From: Will Hilton Date: Tue, 11 Aug 2015 00:03:19 -0400 Subject: [PATCH 4/6] Added example to README --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3c73385..5d93da5 100644 --- a/README.md +++ b/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) From 838fb211e6ec47148499ff038d414e4cfb866769 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Wed, 12 Aug 2015 14:28:51 -0400 Subject: [PATCH 5/6] get tag/untag --- README.md | 6 ++++-- bin/get | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d93da5..1a41fb7 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ same control as git but without the headache of its impossible to remember comma ### 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.* +*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`? +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`? @@ -49,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. diff --git a/bin/get b/bin/get index a842b20..b4bec21 100755 --- a/bin/get +++ b/bin/get @@ -43,6 +43,39 @@ else fi ;; +tag) +echo Tagging +git tag "$2" +;; + +untag) +# See 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) ;; From 6fb7f608e108346f20c0d7cdf22aa4c3e309a623 Mon Sep 17 00:00:00 2001 From: William Hilton Date: Wed, 12 Aug 2015 14:29:46 -0400 Subject: [PATCH 6/6] Hate it when I do that. --- bin/get | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/get b/bin/get index b4bec21..fc2ee22 100755 --- a/bin/get +++ b/bin/get @@ -49,7 +49,7 @@ git tag "$2" ;; untag) -# See if tag exists +# Delete tag (if tag exists) if git rev-parse "$2" >/dev/null 2>&1 then echo Deleting tag "$2"