Thread (4 messages) 4 messages, 4 authors, 2019-10-31

Re: [FR] Allow `git stash create` to include untracked changes

From: Thomas Gummerer <hidden>
Date: 2019-10-31 13:40:39

Possibly related (same subject, not in this thread)

On 10/29, Johannes Schindelin wrote:
So why does `git stash create -u ...` not work? Because the original
design of `git stash create` never intended to take any command-line
arguments other than the stash message. And that design can obviously
not be fixed without breaking backwards compatibility.
Yup that's exactly right.  Not breaking this sort of backwards
compatibility is also why we have both 'git stash save' and 'git stash
push' nowadays.

We did have a similar conversation back when 'git stash push' was
introduced [1].  We almost decided this regression would be okay, but
in the end went with calling 'create_stash -m "$*"' internally to
circumvent the problem.  Now that somebody has an actual usecase we
may or may not find this "regression" acceptable.  I don't have a
strong opinion about it, so this is just to add a little bit of
context here.

[1]: https://public-inbox.org/git/20170206155606.xgkmhg656vuc6uki@sigill.intra.peff.net/
quoted hunk ↗ jump to hunk
What we _could_ do is to add a new command-line option to `git stash
push` that would make it behave like the `create` subsubcommand: _not_
update the `refs/stash` ref but instead print the commit hash.

I am not quite sure how to call this option (`--ephemeral` came to my
mind, as the created commit is not reachable from anywhere and is hence
subject to garbage collection).

A completely different approach would be to allow overriding the ref to
store the stash in, with an empty value triggering the mode where the
ref is not updated but the commit hash would be printed instead. I am
thinking of something like `git stash -r '' push ...`, starting with
this patch:

-- snip --
diff --git a/builtin/stash.c b/builtin/stash.c
index bb4f6d8d762..43b0a155b1d 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1553,6 +1553,8 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
 	struct argv_array args = ARGV_ARRAY_INIT;

 	struct option options[] = {
+		OPT_STRING('r', "ref", &ref_stash, N_("ref"),
+			   N_("override `refs/stash`")),
 		OPT_END()
 	};

-- snap --
The biggest trick will be to make all the code paths safe that assume
that `ref_stash` refers to a valid ref ;-)

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help