Skip to content

Commit f6fa554

Browse files
authored
Merge pull request #939 from SimonTate/feature/force-clear
git-clear: add force option
2 parents c30ac80 + bc8876b commit f6fa554

File tree

5 files changed

+104
-17
lines changed

5 files changed

+104
-17
lines changed

bin/git-clear

+40-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
#!/usr/bin/env bash
2+
PROGNAME="git-clear"
3+
FORCE=0
24

3-
echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: "
4-
read ans
5-
if [ "$ans" == "y" ]
6-
then git clean -d -f -x && git reset --hard
5+
function _usage() {
6+
cat << EOF
7+
usage: $PROGNAME options
8+
usage: $PROGNAME -h|help|?
9+
10+
clear git repository
11+
12+
OPTIONS:
13+
-f, --force Force clear without questioning user
14+
-h, --help, ? Show this message
15+
EOF
16+
}
17+
18+
# Read arguments
19+
while [ "$1" != "" ]; do
20+
case $1 in
21+
-f|--force)
22+
FORCE=1
23+
;;
24+
-h|--help|?)
25+
_usage
26+
exit 1
27+
;;
28+
esac
29+
30+
shift
31+
done
32+
33+
# Only wait for answer if not forced by user
34+
if [[ $FORCE == 0 ]]; then
35+
echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: "
36+
read clean
37+
else
38+
clean=y
39+
fi
40+
41+
if [ "$clean" == "y" ]; then
42+
git clean -d -f -x && git reset --hard
743
fi

etc/git-extras-completion.zsh

+7-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ _git-changelog() {
114114
'(-l --list)'{-l,--list}'[list commits]' \
115115
}
116116

117+
_git-clear() {
118+
_arguments \
119+
'(-f --force)'{-f,--force}'[force clear]' \
120+
'(-h --help)'{-h,--help}'[help message]' \
121+
}
122+
117123
_git-coauthor() {
118124
_arguments \
119125
':co-author[co-author to add]' \
@@ -160,7 +166,7 @@ _git-delete-branch() {
160166

161167
_git-delete-squashed-branches() {
162168
_arguments \
163-
':branch-name:__gitex_branch_names'
169+
':branch-name:__gitex_branch_names'
164170
}
165171

166172

man/git-clear.1

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-CLEAR" "1" "May 2018" "" "Git Extras"
4+
.TH "GIT\-CLEAR" "1" "September 2021" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-clear\fR \- Rigorously clean up a repository
@@ -12,16 +12,31 @@
1212
.SH "DESCRIPTION"
1313
Clears the repository to a state that it looks as if it was freshly cloned with the current HEAD\. Basically it is a git\-reset \-\-hard together with deletion of all untracked files that reside inside the working directory, including those in \.gitignore\.
1414
.
15+
.SH "OPTIONS"
16+
\-f, \-\-force
17+
.
18+
.P
19+
Force the clean, with no warning to the user
20+
.
21+
.P
22+
\-h, \-\-help, ?
23+
.
24+
.P
25+
Display usage
26+
.
1527
.SH "EXAMPLES"
16-
Clears the repo\.
1728
.
18-
.IP "" 4
29+
.IP "\(bu" 4
30+
Clears the repo, with user confirmation required\.
1931
.
20-
.nf
21-
32+
.IP
2233
$ git clear
2334
.
24-
.fi
35+
.IP "\(bu" 4
36+
Clears the repo, without user confirmation\.
37+
.
38+
.IP
39+
$ git clear \-f
2540
.
2641
.IP "" 0
2742
.

man/git-clear.html

+21-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-clear.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ git-clear(1) -- Rigorously clean up a repository
1111
with the current HEAD. Basically it is a git-reset --hard together with
1212
deletion of all untracked files that reside inside the working directory, including those in .gitignore.
1313

14+
## OPTIONS
15+
16+
-f, --force
17+
18+
Force the clean, with no warning to the user
19+
20+
-h, --help, ?
21+
22+
Display usage
23+
1424
## EXAMPLES
1525

16-
Clears the repo.
26+
* Clears the repo, with user confirmation required.
1727

1828
$ git clear
1929

30+
* Clears the repo, without user confirmation.
31+
32+
$ git clear -f
33+
2034
## AUTHOR
2135

2236
Written by Daniel 'grindhold' Brendle &lt;<grindhold@gmx.net>&gt;

0 commit comments

Comments
 (0)