-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #939 from SimonTate/feature/force-clear
git-clear: add force option
- Loading branch information
Showing
5 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <<[email protected]>> | ||
|