-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(git-clear): add --force and --help flags #828
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
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 | ||
_usage() { | ||
PROGNAME="git-clear" | ||
|
||
cat << EOF | ||
usage: $PROGNAME [<options>] | ||
|
||
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. | ||
|
||
|
||
OPTIONS: | ||
-f, --force Don't prompt for confirmation to clear | ||
-h, --help Show this message | ||
|
||
EOF | ||
} | ||
|
||
|
||
FORCE=0 | ||
|
||
while [ "X$1" != "X" ]; do | ||
case $1 in | ||
-f|--force) | ||
FORCE=1 | ||
shift | ||
;; | ||
|
||
-h|--help|help) | ||
_usage | ||
exit 0 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
|
||
if [[ $FORCE == 0 ]]; then | ||
echo -n "Sure? - This command may delete files that cannot be recovered, including those in .gitignore [y/N]: " | ||
read ans | ||
|
||
if [[ "$ans" == "y" ]]; then | ||
FORCE=1 | ||
fi | ||
fi | ||
|
||
|
||
if [[ $FORCE == 1 ]]; then | ||
git clean -d -f -x && git reset --hard | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo -n "Sure? - This command may delete files that cannot be recovered. Files and directories in .gitignore will be preserved [y/N]: " | ||
read ans | ||
if [ "$ans" == "y" ] | ||
then git clean -d -f && git reset --hard | ||
_usage() { | ||
PROGNAME="git-clear-soft" | ||
|
||
cat << EOF | ||
usage: $PROGNAME [<options>] | ||
|
||
Clears the repository to a state that it looks as if it was freshly cloned | ||
with the current HEAD, however, preserving all changes that are located in files and directories listed in .gitignore. It is a git-reset --hard together with | ||
deletion of all untracked files that reside inside the working directory, excluding those in .gitignore. | ||
|
||
OPTIONS: | ||
-f, --force Don't prompt for confirmation to clear | ||
-h, --help Show this message | ||
|
||
EOF | ||
} | ||
|
||
|
||
FORCE=0 | ||
|
||
while [ "X$1" != "X" ]; do | ||
case $1 in | ||
-f|--force) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
FORCE=1 | ||
shift | ||
;; | ||
|
||
-h|--help|help) | ||
_usage | ||
exit 0 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
|
||
if [[ $FORCE == 0 ]]; then | ||
echo -n "Sure? - This command may delete files that cannot be recovered. Files and directories in .gitignore will be preserved [y/N]: " | ||
read ans | ||
|
||
if [[ "$ans" == "y" ]]; then | ||
FORCE=1 | ||
fi | ||
fi | ||
|
||
|
||
if [[ $FORCE == 1 ]]; then | ||
git clean -d -f && git reset --hard | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,3 +158,29 @@ _git_undo(){ | |
_git_browse(){ | ||
__git_complete_remote_or_refspec | ||
} | ||
|
||
_git_clear(){ | ||
local s_opts=( '-h' '-f' ) | ||
local l_opts=( | ||
'--force' | ||
'--help' | ||
) | ||
local merged_opts_str="" | ||
merged_opts_str+="$(printf "%s " "${s_opts[@]}")" | ||
merged_opts_str+="$(printf "%s " "${l_opts[@]}")" | ||
|
||
__gitcomp "$merged_opts_str" | ||
} | ||
|
||
_git_clear_soft(){ | ||
local s_opts=( '-h' '-f' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just let |
||
local l_opts=( | ||
'--force' | ||
'--help' | ||
) | ||
local merged_opts_str="" | ||
merged_opts_str+="$(printf "%s " "${s_opts[@]}")" | ||
merged_opts_str+="$(printf "%s " "${l_opts[@]}")" | ||
|
||
__gitcomp "$merged_opts_str" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a consistent indent style.