Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-clear: add force option #939

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions bin/git-clear
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
#!/usr/bin/env bash
PROGNAME="git-clear"
FORCE=0

echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: "
read ans
if [ "$ans" == "y" ]
then git clean -d -f -x && git reset --hard
function _usage() {
cat << EOF
usage: $PROGNAME options
usage: $PROGNAME -h|help|?

clear git repository

OPTIONS:
-f, --force Force clear without questioning user
-h, --help, ? Show this message
EOF
}

# Read arguments
while [ "$1" != "" ]; do
case $1 in
-f|--force)
FORCE=1
;;
-h|--help|?)
_usage
exit 1
;;
esac

shift
done

# Only wait for answer if not forced by user
if [[ $FORCE == 0 ]]; then
echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: "
read clean
else
clean=y
fi

if [ "$clean" == "y" ]; then
git clean -d -f -x && git reset --hard
fi
8 changes: 7 additions & 1 deletion etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ _git-changelog() {
'(-l --list)'{-l,--list}'[list commits]' \
}

_git-clear() {
_arguments \
'(-f --force)'{-f,--force}'[force clear]' \
'(-h --help)'{-h,--help}'[help message]' \
}

_git-coauthor() {
_arguments \
':co-author[co-author to add]' \
Expand Down Expand Up @@ -160,7 +166,7 @@ _git-delete-branch() {

_git-delete-squashed-branches() {
_arguments \
':branch-name:__gitex_branch_names'
':branch-name:__gitex_branch_names'
}


Expand Down
27 changes: 21 additions & 6 deletions man/git-clear.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-CLEAR" "1" "May 2018" "" "Git Extras"
.TH "GIT\-CLEAR" "1" "September 2021" "" "Git Extras"
.
.SH "NAME"
\fBgit\-clear\fR \- Rigorously clean up a repository
Expand All @@ -12,16 +12,31 @@
.SH "DESCRIPTION"
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\.
.
.SH "OPTIONS"
\-f, \-\-force
.
.P
Force the clean, with no warning to the user
.
.P
\-h, \-\-help, ?
.
.P
Display usage
.
.SH "EXAMPLES"
Clears the repo\.
.
.IP "" 4
.IP "\(bu" 4
Clears the repo, with user confirmation required\.
.
.nf

.IP
$ git clear
.
.fi
.IP "\(bu" 4
Clears the repo, without user confirmation\.
.
.IP
$ git clear \-f
.
.IP "" 0
.
Expand Down
26 changes: 21 additions & 5 deletions man/git-clear.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion man/git-clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ git-clear(1) -- Rigorously clean up a repository
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.

## OPTIONS

-f, --force

Force the clean, with no warning to the user

-h, --help, ?

Display usage

## EXAMPLES

Clears the repo.
* Clears the repo, with user confirmation required.

$ git clear

* Clears the repo, without user confirmation.

$ git clear -f

## AUTHOR

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