Hi,
While preparing an RFC about adding option support to
`git stash create`, I was looking more closely at `-u` and
`-a` when I noticed something interesting about how they
behave in `git stash push` and `git stash save`.
The `-u` option includes untracked files, while `-a` includes
both untracked and ignored files.
However, when both options are given, their order matters:
git stash push -u -a
untracked and ignored files
git stash push -a -u
untracked files only
Both `--no-include-untracked` and `--no-all` cancel the
selection of untracked and ignored files, regardless of
whether `-u` or `-a` was specified earlier:
git stash push -a --no-include-untracked
neither untracked nor ignored files
git stash push -a --no-include-untracked -u
untracked files only
The documentation explains each option separately, but not what
happens when they are combined. This may be confusing for users.
We could change how these options interact, but that raises
several questions, as I'll discuss below. Another possibility
would be to document the current behavior.
For example, the documentation could say something like:
With `stash push` and `stash save`, `-u` and `-a` are
processed in the order given. When both are specified,
the last one takes effect. Thus, `-u -a` includes both
untracked and ignored files, while `-a -u` includes
only untracked files.
Either `--no-include-untracked` or `--no-all` clears
the selection, regardless of whether it came from `-u`
or `-a`. A later `-u` or `-a` can make a new selection.
Documenting the current behavior as it stands might lead
users to expect it to remain unchanged. Perhaps it would
be better not to document it. On the other hand, leaving it
undocumented means users have to discover these interactions
themselves.
Now, I'd like to think a little about how `-u` and `-a`
could behave when used together.
(A) Make `-a` take precedence over `-u` when both are enabled,
regardless of order.
Both `-u -a` and `-a -u` would include untracked and ignored
files. Today, `-a -u` leaves ignored files alone.
(B) Treat `-u` and `-a` as mutually exclusive, as `git add`
does with `-u` and `-A`.
If both remain enabled after option parsing, this would be an
error. Both `-u -a` and `-a -u` would then fail, whereas they
are currently accepted.
For (A) and (B), I'll assume `-u` and `-a` are tracked
separately, with each negated option canceling only its
corresponding positive option. This seems easier to
reason about, so I'll use that assumption here. A
negated option would not cause an error even if its
positive option had not been given.
For example, `-a -u --no-all` would leave `-u` enabled,
selecting untracked files only, whereas it currently
selects neither class.
Similarly, `-a --no-include-untracked` would leave
`-a` enabled and select both untracked and ignored files,
unlike today.
(C) Add `-X` (or `--include-ignored`) for ignored files only,
similar to `git clean -X`.
For (C), I'll consider `-u` and `-X` as two independent
flags instead.
Here, `-a` would be an alias for `-u -X`, and `--no-all`
would be an alias for `--no-include-untracked` and
`--no-include-ignored` together.
This would allow untracked and ignored files to be selected
independently. Both `-u -a` and `-a -u` would select both
classes.
The negated options would also work independently.
One possible advantage is that each option's effect would
follow directly from its meaning, even in combinations.
For example:
-a --no-include-untracked
ignored files only
-a --no-include-ignored
untracked files only
-a --no-all
neither untracked nor ignored files
`-a --no-include-untracked` illustrates the difference:
unlike (A) and (B), (C) would remove untracked files from
the selection, as the negated option suggests. This would
also differ from today's behavior.
To compare some less obvious combinations, I made this
table. I assume the documentation would describe (B)'s
conflict error and (C)'s aliases. Each cell shows the
result and whether I find it intuitive (Yes/No):
Option sequence Current A B C
-u -a UI/Yes UI/Yes Err/Yes UI/Yes
-a -u U/No UI/Yes Err/Yes UI/Yes
-a --no-include-untracked -/No UI/No UI/No I/Yes
-a -u --no-all -/Yes U/No U/No -/Yes
-u -a --no-all -/Yes U/No U/No -/Yes
-a -u --no-include-untracked -/No UI/No UI/No I/Yes
-a --no-include-untracked -u U/No UI/Yes Err/Yes UI/Yes
-a --no-all -u U/Yes U/Yes U/Yes U/Yes
-a --no-include-ignored N/A/- N/A/- N/A/- U/Yes
Here, U means untracked files, I ignored files, UI both,
and "-" neither. Err means an error; N/A means the option
is not available.
Writing this out, I find (C) more consistent than I had
expected, and I'm tempted to favor it. But it would change
the behavior of some existing combinations, so backward
compatibility is still a concern.
(I'm not sure how difficult (C) would be to implement.)
For now, I think documenting the current behavior would
be the better step. If needed, we could continue to discuss
possible changes separately. What do you think?
Thanks,
Kazumasa
[RFC] stash: interaction between -u and -a
- From
- kazu…@kanamei.com (重田一聖)
- Organization
- Usenet Network
- Message-ID
- <CANU…@mail.gmail.com>
- Date
- Newsgroups
- linux.kernel.git