From bc8876b063b8c2d81d9851591a29728c0b6d1149 Mon Sep 17 00:00:00 2001 From: Simon Tate Date: Thu, 9 Sep 2021 21:29:36 +0100 Subject: [PATCH] git-clear: add force option Add a new -f/--force option to git-clear to allow usage in scripts, or without user input. Add -h/--help/? for help Also update the manual for git-clear for these changes. --- bin/git-clear | 44 +++++++++++++++++++++++++++++++---- etc/git-extras-completion.zsh | 8 ++++++- man/git-clear.1 | 27 ++++++++++++++++----- man/git-clear.html | 26 +++++++++++++++++---- man/git-clear.md | 16 ++++++++++++- 5 files changed, 104 insertions(+), 17 deletions(-) diff --git a/bin/git-clear b/bin/git-clear index 52bd14d6a..41379ee77 100755 --- a/bin/git-clear +++ b/bin/git-clear @@ -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 diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index a6c7fe91b..2d8bf579c 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -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]' \ @@ -160,7 +166,7 @@ _git-delete-branch() { _git-delete-squashed-branches() { _arguments \ - ':branch-name:__gitex_branch_names' + ':branch-name:__gitex_branch_names' } diff --git a/man/git-clear.1 b/man/git-clear.1 index 7c00138aa..b458edf4e 100644 --- a/man/git-clear.1 +++ b/man/git-clear.1 @@ -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 @@ -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 . diff --git a/man/git-clear.html b/man/git-clear.html index 4d4c9a40b..7a7fa9f1f 100644 --- a/man/git-clear.html +++ b/man/git-clear.html @@ -56,6 +56,7 @@ NAME SYNOPSIS DESCRIPTION + OPTIONS EXAMPLES AUTHOR REPORTING BUGS @@ -83,16 +84,31 @@

DESCRIPTION

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.

+ -
$ git clear
-

AUTHOR

-

Written by Daniel 'grindhold' Brendle <grindhold@gmx.net>

+

Written by Daniel 'grindhold' Brendle <grindhold@gmx.net>

REPORTING BUGS

@@ -105,7 +121,7 @@

SEE ALSO

  1. -
  2. May 2018
  3. +
  4. September 2021
  5. git-clear(1)
diff --git a/man/git-clear.md b/man/git-clear.md index 3475d02e0..be911a488 100644 --- a/man/git-clear.md +++ b/man/git-clear.md @@ -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 <>