From 1f2b3ea2036f81135bedcf467c8d66f6fccdb538 Mon Sep 17 00:00:00 2001 From: nickl- Date: Sun, 22 Jul 2012 22:51:57 +0200 Subject: [PATCH 1/2] Alphabetically sorted bash_completion. Makes it easier to work with and slightly optimizes things for bash_completion which sorts these completions alphabetically. --- etc/bash_completion.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index e37fa74..db68dfa 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -1,5 +1,9 @@ # bash completion support for git-extras. +_git_bug(){ + __git_extras_workflow "bug" +} + _git_changelog(){ __gitcomp "--list" } @@ -28,6 +32,14 @@ _git_extras(){ __gitcomp "--version update" } +__git_extras_workflow(){ + __gitcomp "$(__git_heads | grep ^$1/ | sed s/^$1\\///g) finish" +} + +_git_feature(){ + __git_extras_workflow "feature" +} + _git_graft(){ __gitcomp "$(__git_heads)" } @@ -45,22 +57,14 @@ _git_ignore(){ esac } -_git_squash(){ - __gitcomp "$(__git_heads)" -} - -__git_extras_workflow(){ - __gitcomp "$(__git_heads | grep ^$1/ | sed s/^$1\\///g) finish" -} - -_git_feature(){ - __git_extras_workflow "feature" -} - _git_refactor(){ __git_extras_workflow "refactor" } -_git_bug(){ - __git_extras_workflow "bug" +_git_squash(){ + __gitcomp "$(__git_heads)" +} + +_git_undo(){ + __gitcomp "--hard --soft -h -s" } From 501d4b2759663cbd1985bf4b059ebce5e2c0fe47 Mon Sep 17 00:00:00 2001 From: nickl- Date: Sun, 22 Jul 2012 22:57:19 +0200 Subject: [PATCH 2/2] Recommit of @d153e9c Changes to PR #114. Added -s --soft arguments as well. Default roll-back one with HEAD^ and only using ~ if commit count more than 1. Added auto complete. Updated documentation. Attitude adjustment: don't throw errors and say NO as suggested in #114, have a can do attitude instead, leave the errors up to git to report. --- bin/git-undo | 38 +++++++++++++++----------------------- man/git-undo.1 | 14 ++++++++++---- man/git-undo.html | 12 ++++++++---- man/git-undo.md | 12 ++++++++---- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/bin/git-undo b/bin/git-undo index aedc844..683a48e 100755 --- a/bin/git-undo +++ b/bin/git-undo @@ -1,27 +1,19 @@ #!/bin/sh -hard='no' -digit=1 +back="^" -parseArgs () { - for var in "$@"; do - if [ "$var" = "--hard" -o "$var" = "-h" ]; then - hard='yes'; - elif `echo $var | grep -q [^[:digit:]]`; then - echo "You entered an invalid option. Valid options are [--hard|-h] [commitcount]." 1>&2 - exit 1; - else - digit=$var - fi - done -} - -parseArgs $@ - -if [ "$hard" = "yes" ]; then - git reset --hard HEAD~$digit -else - git reset --soft HEAD~$digit - git reset -fi +case "$1" in + -h|--hard) + test $2 -gt 1 > /dev/null 2>&1 && back="~$2" + git reset --hard HEAD$back && exit 0; + ;; + -s|--soft) + test $2 -gt 1 > /dev/null 2>&1 && back="~$2" + ;; + *) + test $1 -gt 1 > /dev/null 2>&1 && back="~$1" + ;; +esac +git reset --soft HEAD$back +git reset diff --git a/man/git-undo.1 b/man/git-undo.1 index 1172422..7dd8dee 100644 --- a/man/git-undo.1 +++ b/man/git-undo.1 @@ -7,16 +7,16 @@ \fBgit\-undo\fR \- Remove latest commits . .SH "SYNOPSIS" -\fBgit\-undo\fR [] [\-\-hard|\-h] +\fBgit\-undo\fR [] [\-s, \-\-soft, \-h, \-\-hard] . .SH "DESCRIPTION" Removes the latest commits\. . .SH "OPTIONS" - +\-\-soft or \-s . .P -Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit\. +This is the default, only rolls back the commit but changes remain un\-staged\. . .P \-\-hard or \-h @@ -24,6 +24,12 @@ Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit .P This option wipes your commit(s), so that your changes cannot be recovered\. Use with care\. . +.P + +. +.P +Number of commits to remove\. Defaults to \fI1\fR, thus remove the latest commit\. +. .SH "EXAMPLES" Removes the latest commit\. . @@ -51,7 +57,7 @@ $ git undo 3 .IP "" 0 . .SH "AUTHOR" -Written by Kenneth Reitz <\fIme@kennethreitz\.com\fR> +Written by Kenneth Reitz <\fIme@kennethreitz\.com\fR> and Nick Lombard <\fIgithub@jigsoft\.co\.za\fR> . .SH "REPORTING BUGS" <\fIhttp://github\.com/visionmedia/git\-extras/issues\fR> diff --git a/man/git-undo.html b/man/git-undo.html index 1eaed2a..bbcd9d7 100644 --- a/man/git-undo.html +++ b/man/git-undo.html @@ -76,7 +76,7 @@

SYNOPSIS

-

git-undo [<commitcount>] [--hard|-h]

+

git-undo [<commitcount>] [-s, --soft, -h, --hard]

DESCRIPTION

@@ -84,14 +84,18 @@

OPTIONS

-

<commitcount>

+

--soft or -s

-

Number of commits to remove. Defaults to 1, thus remove the latest commit.

+

This is the default, only rolls back the commit but changes remain un-staged.

--hard or -h

This option wipes your commit(s), so that your changes cannot be recovered. Use with care.

+

<commitcount>

+ +

Number of commits to remove. Defaults to 1, thus remove the latest commit.

+

EXAMPLES

Removes the latest commit.

@@ -106,7 +110,7 @@

AUTHOR

-

Written by Kenneth Reitz <me@kennethreitz.com>

+

Written by Kenneth Reitz <me@kennethreitz.com> and Nick Lombard <github@jigsoft.co.za>

REPORTING BUGS

diff --git a/man/git-undo.md b/man/git-undo.md index 82694a4..c3f81bf 100644 --- a/man/git-undo.md +++ b/man/git-undo.md @@ -3,7 +3,7 @@ git-undo(1) -- Remove latest commits ## SYNOPSIS -`git-undo` [<commitcount>] [--hard|-h] +`git-undo` [<commitcount>] [-s, --soft, -h, --hard] ## DESCRIPTION @@ -11,14 +11,18 @@ git-undo(1) -- Remove latest commits ## OPTIONS - <commitcount> + --soft or -s - Number of commits to remove. Defaults to *1*, thus remove the latest commit. + This is the default, only rolls back the commit but changes remain un-staged. --hard or -h This option wipes your commit(s), so that your changes cannot be recovered. Use with care. + <commitcount> + + Number of commits to remove. Defaults to *1*, thus remove the latest commit. + ## EXAMPLES Removes the latest commit. @@ -31,7 +35,7 @@ git-undo(1) -- Remove latest commits ## AUTHOR -Written by Kenneth Reitz <> +Written by Kenneth Reitz <> and Nick Lombard <> ## REPORTING BUGS