From: "Nadav Goldstein via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <derrickstolee@github.com>,
Nadav Goldstein <nadav.goldstein96@gmail.com>,
Nadav Goldstein <nadav.goldstein96@gmail.com>
Subject: [PATCH v3] Introduced force flag to the git stash clear subcommand.
Date: Tue, 20 Jun 2023 00:03:34 +0000 [thread overview]
Message-ID: <pull.1232.v3.git.1687219414844.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1232.v2.git.1653286345.gitgitgadget@gmail.com>
From: Nadav Goldstein <nadav.goldstein96@gmail.com>
stash clean subcommand now support the force flag, along
with the configuration var stash.requireforce, that if
set to true, will make git stash clear fail unless supplied
with force flag.
Signed-off-by: Nadav Goldstein <nadav.goldstein96@gmail.com>
---
stash clear: added safety flag for stash clear subcommand
This patch started to solve the issue of easy trigger of git stash
clear. I first went with using an interactive (-i) flag to stash clear,
but following the conversations I had here I understood that it was a
misleading flag and not a good direction for implementation.
So in this version of the patch (v3), I went with Junio proposal to
introduce force flag to the clean subcommand.
Thanks!
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1232%2Fnadav96%2Fclear-stash-prompt-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1232/nadav96/clear-stash-prompt-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1232
Range-diff vs v2:
1: 13bc75a2b05 < -: ----------- add-menu: added add-menu to lib objects
2: 7271a285d18 < -: ----------- clean: refector to the interactive part of clean
-: ----------- > 1: 6150ec27b5a Introduced force flag to the git stash clear subcommand.
Documentation/git-stash.txt | 12 ++++++++++--
builtin/stash.c | 12 +++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index f4bb6114d91..e95410d507e 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -20,7 +20,7 @@ SYNOPSIS
[--] [<pathspec>...]]
'git stash' save [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
[-u | --include-untracked] [-a | --all] [<message>]
-'git stash' clear
+'git stash' clear [-f | --force]
'git stash' create [<message>]
'git stash' store [(-m | --message) <message>] [-q | --quiet] <commit>
@@ -130,7 +130,7 @@ the stash entry is applied on top of the commit that was HEAD at the
time `git stash` was run, it restores the originally stashed state
with no conflicts.
-clear::
+clear [-f|--force]::
Remove all the stash entries. Note that those entries will then
be subject to pruning, and may be impossible to recover (see
'Examples' below for a possible strategy).
@@ -208,6 +208,14 @@ to learn how to operate the `--patch` mode.
The `--patch` option implies `--keep-index`. You can use
`--no-keep-index` to override this.
+-f::
+--force::
+ This option is only valid for `clear` command
++
+If the Git configuration variable stash.requireForce is set
+to true, 'git stash clear' will refuse to remove all the stash
+entries unless given -f.
+
-S::
--staged::
This option is only valid for `push` and `save` commands.
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe384..d037bc4f69c 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -53,7 +53,7 @@
#define BUILTIN_STASH_CREATE_USAGE \
N_("git stash create [<message>]")
#define BUILTIN_STASH_CLEAR_USAGE \
- "git stash clear"
+ "git stash clear [-f | --force]"
static const char * const git_stash_usage[] = {
BUILTIN_STASH_LIST_USAGE,
@@ -122,6 +122,7 @@ static const char * const git_stash_save_usage[] = {
static const char ref_stash[] = "refs/stash";
static struct strbuf stash_index_path = STRBUF_INIT;
+static int clear_require_force = 0;
/*
* w_commit is set to the commit containing the working tree
@@ -246,7 +247,9 @@ static int do_clear_stash(void)
static int clear_stash(int argc, const char **argv, const char *prefix)
{
+ int force = 0;
struct option options[] = {
+ OPT__FORCE(&force, N_("force"), PARSE_OPT_NOCOMPLETE),
OPT_END()
};
@@ -258,6 +261,9 @@ static int clear_stash(int argc, const char **argv, const char *prefix)
return error(_("git stash clear with arguments is "
"unimplemented"));
+ if (!force && clear_require_force)
+ return error(_("fatal: stash.requireForce set to true and -f was not given; refusing to clear stash"));
+
return do_clear_stash();
}
@@ -851,6 +857,10 @@ static int git_stash_config(const char *var, const char *value, void *cb)
show_include_untracked = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "stash.requireforce")) {
+ clear_require_force = git_config_bool(var, value);
+ return 0;
+ }
return git_diff_basic_config(var, value, cb);
}
base-commit: d7d8841f67f29e6ecbad85a11805c907d0f00d5d
--
gitgitgadget
next prev parent reply other threads:[~2023-06-20 0:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-15 21:18 [PATCH] stash: added safety flag for stash clear subcommand Nadav Goldstein via GitGitGadget
2022-05-16 3:17 ` Junio C Hamano
2022-05-23 6:12 ` [PATCH v2 0/2] stash clear: " Nadav Goldstein via GitGitGadget
2022-05-23 6:12 ` [PATCH v2 1/2] add-menu: added add-menu to lib objects Nadav Goldstein via GitGitGadget
2022-05-23 20:03 ` Derrick Stolee
2022-05-23 20:35 ` Junio C Hamano
2022-05-23 6:12 ` [PATCH v2 2/2] clean: refector to the interactive part of clean Nadav Goldstein via GitGitGadget
2022-05-23 19:45 ` Derrick Stolee
2022-05-23 19:33 ` [PATCH v2 0/2] stash clear: added safety flag for stash clear subcommand Derrick Stolee
2023-06-20 0:03 ` Nadav Goldstein via GitGitGadget [this message]
2023-06-20 6:25 ` [PATCH v3] Introduced force flag to the git " Junio C Hamano
2023-06-20 19:54 ` Nadav Goldstein
2023-06-20 20:46 ` Junio C Hamano
2023-06-20 21:01 ` Eric Sunshine
2023-06-20 21:42 ` Nadav Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1232.v3.git.1687219414844.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=nadav.goldstein96@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).