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

feat(git-clear): add --force and --help flags #828

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
53 changes: 49 additions & 4 deletions bin/git-clear
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)
Copy link
Collaborator

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.

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
52 changes: 48 additions & 4 deletions bin/git-clear-soft
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
26 changes: 26 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just let _git_clear and _git_clear_soft call the same helper function?

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"
}
14 changes: 13 additions & 1 deletion man/git-clear-soft.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\-SOFT" "1" "October 2017" "" "Git Extras"
.TH "GIT\-CLEAR\-SOFT" "1" "April 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-clear\-soft\fR \- Soft clean up a repository
Expand All @@ -12,6 +12,18 @@
.SH "DESCRIPTION"
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\.
.
.SH "OPTIONS"
\-f, \-\-force
.
.P
Don\'t prompt for confirmation to clear
.
.P
\-h, \-\-help
.
.P
Show a help message with basic usage information\.
.
.SH "EXAMPLES"
Clears the repo\.
.
Expand Down
15 changes: 13 additions & 2 deletions man/git-clear-soft.html

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

10 changes: 10 additions & 0 deletions man/git-clear-soft.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ git-clear-soft(1) -- Soft clean up a repository
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 a help message with basic usage information.

## EXAMPLES

Clears the repo.
Expand Down
14 changes: 13 additions & 1 deletion 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" "April 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-clear\fR \- Rigorously clean up a repository
Expand All @@ -12,6 +12,18 @@
.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
Don\'t prompt for confirmation to clear
.
.P
\-h, \-\-help
.
.P
Show a help message with basic usage information\.
.
.SH "EXAMPLES"
Clears the repo\.
.
Expand Down
15 changes: 13 additions & 2 deletions man/git-clear.html

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

10 changes: 10 additions & 0 deletions man/git-clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ 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

Don't prompt for confirmation to clear

-h, --help

Show a help message with basic usage information.

## EXAMPLES

Clears the repo.
Expand Down