Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f289367

Browse files
committed
Add git-abandon
1 parent 115d8bb commit f289367

5 files changed

Lines changed: 254 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,21 @@ git fixup [(-b|--message-body) <message-body>] [<commit>]
8787
git fixup [(-h|--help)]
8888
```
8989

90+
### [abandon][]
91+
92+
Used to drop a count or range of stashes.
93+
94+
```bash
95+
git abandon <count>
96+
git abandon <start>..<end>
97+
git abandon (-h|--help)
98+
git abandon (-v|--version)
99+
```
100+
90101
[state]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-state.1.html
91102
[snapshot]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-snapshot.1.html
92103
[changes]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-changes.1.html
93104
[settings]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-settings.1.html
94105
[upstream]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-upstream.1.html
95106
[fixup]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-fixup.1.html
107+
[abandon]: http://htmlpreview.github.io/?https://raw.githubusercontent.com/Brickstertwo/git-commands/master/man/man1/git-abandon.1.html

bin/git-abandon

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! /bin/bash
2+
3+
VERSION="0.1.0"
4+
5+
. git-commands-utils
6+
7+
while getopts ":hv-:" opt; do
8+
case $opt in
9+
-)
10+
case "${OPTARG}" in
11+
help) show_help;;
12+
version) show_version "$VERSION";;
13+
*) error "Unimplemented option --${OPTARG}";;
14+
esac
15+
;;
16+
h) show_help;;
17+
v) show_version "$VERSION";;
18+
\?) error "Invalid option: -$OPTARG";;
19+
:) error "Option -$OPTARG requires an argument.";;
20+
*) error "Unimplemented option: -$OPTARG";;
21+
esac
22+
done
23+
24+
start_count=0
25+
end_count=0
26+
27+
input=${!OPTIND}
28+
range_regex="^([[:digit:]]+)\.\.([[:digit:]])+$"
29+
digits_regex="^[[:digit:]]+$"
30+
if [[ -z "$input" ]]; then
31+
error_and_continue "a number of stashes to drop must be specified"
32+
usage_error "git abandon <count>" "git abandon <start>..<end>"
33+
elif [[ "$input" =~ $range_regex ]]; then
34+
start_count="${BASH_REMATCH[1]}"
35+
end_count="${BASH_REMATCH[2]}"
36+
elif [[ "$input" =~ $digits_regex ]]; then
37+
start_count=0
38+
end_count=$((input-1))
39+
else
40+
error_and_continue "a number of stashes to drop must be specified"
41+
error_and_continue "used '$input'"
42+
usage_error "git abandon <count>" "git abandon <start>..<end>"
43+
fi
44+
45+
# adjust for current stash count
46+
stash_list=$(git stash list)
47+
IFS=$'\n' read -rd '' -a stash_list <<< "$stash_list"
48+
stash_list_count="${#stash_list[@]}"
49+
50+
if (( "$start_count" >= "$stash_list_count" )); then
51+
error_and_continue "start too high"
52+
error "only $stash_list_count stashes exist"
53+
elif (( "$end_count" >= "$stash_list_count" )); then
54+
end_count=$(($stash_list_count-1))
55+
fi
56+
57+
drop_count=$((end_count-start_count))
58+
59+
for ((i=0;i<=$drop_count;i++)); do
60+
git stash drop stash@{"$start_count"}
61+
done

man/man1/git-abandon.1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-ABANDON" "1" "March 2015" "" ""
5+
.
6+
.SH "NAME"
7+
\fBgit\-abandon\fR \- drops a count or range of stashes
8+
.
9+
.SH "SYNOPSIS"
10+
\fBgit abandon\fR \fIcount\fR
11+
.
12+
.br
13+
\fBgit abandon\fR \fIstart\fR\.\.\fIend\fR
14+
.
15+
.br
16+
\fBgit abandon\fR (\-h|\-\-help)
17+
.
18+
.br
19+
\fBgit abandon\fR (\-v|\-\-version)
20+
.
21+
.SH "DESCRIPTION"
22+
\fBgit\-abandon\fR is a shortcut for when you need to drop some, but not all, stashes\. Stashes can be dropped using a count or a range\. If you want to drop all your stashes, just use \fBgit stash clear\fR\.
23+
.
24+
.SH "OPTIONS"
25+
.
26+
.TP
27+
\fIcount\fR
28+
A count of stashes to drop starting at 0\. This is equivalent to \fBgit abandon 0\.\.$((<count>\-1))\fR
29+
.
30+
.TP
31+
\fIstart\fR\.\.\fIend\fR
32+
Drop a range of stashes\. Both \fIstart\fR and \fIend\fR are inclusive\.
33+
.
34+
.TP
35+
\fB\-h\fR|\fB\-\-help\fR
36+
Display git\-abandon man page\.
37+
.
38+
.TP
39+
\fB\-v\fR|\fB\-\-version\fR
40+
Print version\.
41+
.
42+
.SH "SEE ALSO"
43+
git\-stash(1) \fIhttp://git\-scm\.com/docs/git\-stash\fR

man/man1/git-abandon.1.html

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/man1/git-abandon.ronn

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# git-abandon(1) -- drops a count or range of stashes
2+
3+
## SYNOPSIS
4+
5+
`git abandon` <count><br>
6+
`git abandon` <start>..<end><br>
7+
`git abandon` (-h|--help)<br>
8+
`git abandon` (-v|--version)
9+
10+
## DESCRIPTION
11+
12+
`git-abandon` is a shortcut for when you need to drop some, but not all, stashes. Stashes can be dropped using a count or a range. If you want to drop all your stashes, just use `git stash clear`.
13+
14+
## OPTIONS
15+
16+
* <count>:
17+
A count of stashes to drop starting at 0. This is equivalent to `git abandon 0..$((<count>-1))`
18+
19+
* <start>..<end>:
20+
Drop a range of stashes. Both <start> and <end> are inclusive.
21+
22+
* `-h`|`--help`:
23+
Display git-abandon man page.
24+
25+
* `-v`|`--version`:
26+
Print version.
27+
28+
## SEE ALSO
29+
30+
[git-stash(1)](http://git-scm.com/docs/git-stash)

0 commit comments

Comments
 (0)