All of lore.kernel.org
 help / color / mirror / Atom feed
* RFC: git status --amend
@ 2015-03-31 14:59 Sven Strickroth
  2015-03-31 18:04 ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Strickroth @ 2015-03-31 14:59 UTC (permalink / raw)
  To: git, Junio C Hamano

Hi,

for frontends or scripts it would be helpful to be able to use "git
status" for getting the repository status compared to HEAD~1 instead of
only HEAD (as provided by "git commit --amend" in the pre-filled commit
message).

Thus, I'm suggesting to add a "--amend" parameter (or a parameter with a
better naming) to "git status".

What do you think of this idea?

-- 
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-03-31 14:59 RFC: git status --amend Sven Strickroth
@ 2015-03-31 18:04 ` Jeff King
  2015-03-31 18:35   ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2015-03-31 18:04 UTC (permalink / raw)
  To: Sven Strickroth; +Cc: git, Junio C Hamano

On Tue, Mar 31, 2015 at 04:59:27PM +0200, Sven Strickroth wrote:

> for frontends or scripts it would be helpful to be able to use "git
> status" for getting the repository status compared to HEAD~1 instead of
> only HEAD (as provided by "git commit --amend" in the pre-filled commit
> message).
> 
> Thus, I'm suggesting to add a "--amend" parameter (or a parameter with a
> better naming) to "git status".
> 
> What do you think of this idea?

Once upon a time "git status" really was just "git commit --dry-run".
These days it has diverged a bit. But I think you could get what you
want with:

  git commit --dry-run --amend

It even supports alternate styles like --short.

-Peff

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-03-31 18:04 ` Jeff King
@ 2015-03-31 18:35   ` Junio C Hamano
  2015-04-01  8:43     ` David Aguilar
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-03-31 18:35 UTC (permalink / raw)
  To: Jeff King; +Cc: Sven Strickroth, git

Jeff King <peff@peff.net> writes:

> On Tue, Mar 31, 2015 at 04:59:27PM +0200, Sven Strickroth wrote:
>
>> for frontends or scripts it would be helpful to be able to use "git
>> status" for getting the repository status compared to HEAD~1 instead of
>> only HEAD (as provided by "git commit --amend" in the pre-filled commit
>> message).
>> 
>> Thus, I'm suggesting to add a "--amend" parameter (or a parameter with a
>> better naming) to "git status".
>> 
>> What do you think of this idea?
>
> Once upon a time "git status" really was just "git commit --dry-run".
> These days it has diverged a bit. But I think you could get what you
> want with:
>
>   git commit --dry-run --amend
>
> It even supports alternate styles like --short.

I think everything you said is correct, but your "diverged a bit"
may hide one difference that could be crucial depending on the use
case: pathspec.

What "git commit --dry-run [--other-options] <pathspec>" does, and
what "git status [--other-options] <pathspec>" does, are different.

With or without --dry-run, to "git commit", <pathspec> tells the
command to update the index at the paths specified by it from the
working tree contents before proceeding (the contents recorded for
the other paths depend on the use of -o or -i option).  But ever
since "git status" departed from being "git commit -n", a pathspec
given to the command means completely different thing.

After working on various parts of the tree, planning to conclude the
current work with "commit", "git status directory/" is a good way to
see what you did in that directory without seeing what you did
outside (which will be included in the commit, too).

But what you get from "git commit --no-edit --dry-run directory/"
would be different; it would show all the changes in the working
tree inside directory/, including the ones that you deliberately
left out of the index, as paths to be committed.

Having said all that, I am a bit torn on this topic.  Just like "git
status" is a way to ask "I've worked so far, planning to conclude
this with 'git commit'; tell me what I have achieved so far that are
in the index and in the working tree, possibly limiting to these
paths?", I think it is a reasonable thing to ask the same question
with "s/git commit/git commit --amend/".

One workaround might be to

    git reset --soft HEAD^
    git status [<pathspec>]
    ...
    git commit -c @{1}

but that is simply too error prone and ugly.  I would say it would
be better if "status" knows how to answer that "I am planning to
conclude with 'git commit --amend'" question.

The reason why I am torn is because I do not think "status --amend"
is a sensible name for that option.  "status" is not about amending
anything.

If the normal "status" is "give me status for the next commit", this
new mode would be "give me status for the 'commit --amend'".  Naming
it "git status --for-amend" crossed my mind, but it does not sound
great to me, either.

So...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-03-31 18:35   ` Junio C Hamano
@ 2015-04-01  8:43     ` David Aguilar
  2015-04-01 17:16       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: David Aguilar @ 2015-04-01  8:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Sven Strickroth, git

On Tue, Mar 31, 2015 at 11:35:17AM -0700, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
> 
> > On Tue, Mar 31, 2015 at 04:59:27PM +0200, Sven Strickroth wrote:
> >
> >> for frontends or scripts it would be helpful to be able to use "git
> >> status" for getting the repository status compared to HEAD~1 instead of
> >> only HEAD (as provided by "git commit --amend" in the pre-filled commit
> >> message).
> >> 
> >> Thus, I'm suggesting to add a "--amend" parameter (or a parameter with a
> >> better naming) to "git status".
> >> 
> >> What do you think of this idea?
> >
> > Once upon a time "git status" really was just "git commit --dry-run".
> > These days it has diverged a bit. But I think you could get what you
> > want with:
> >
> >   git commit --dry-run --amend
> >
> > It even supports alternate styles like --short.
> 
> I think everything you said is correct, but your "diverged a bit"
> may hide one difference that could be crucial depending on the use
> case: pathspec.
> 
> What "git commit --dry-run [--other-options] <pathspec>" does, and
> what "git status [--other-options] <pathspec>" does, are different.
> 
> With or without --dry-run, to "git commit", <pathspec> tells the
> command to update the index at the paths specified by it from the
> working tree contents before proceeding (the contents recorded for
> the other paths depend on the use of -o or -i option).  But ever
> since "git status" departed from being "git commit -n", a pathspec
> given to the command means completely different thing.
> 
> After working on various parts of the tree, planning to conclude the
> current work with "commit", "git status directory/" is a good way to
> see what you did in that directory without seeing what you did
> outside (which will be included in the commit, too).
> 
> But what you get from "git commit --no-edit --dry-run directory/"
> would be different; it would show all the changes in the working
> tree inside directory/, including the ones that you deliberately
> left out of the index, as paths to be committed.
> 
> Having said all that, I am a bit torn on this topic.  Just like "git
> status" is a way to ask "I've worked so far, planning to conclude
> this with 'git commit'; tell me what I have achieved so far that are
> in the index and in the working tree, possibly limiting to these
> paths?", I think it is a reasonable thing to ask the same question
> with "s/git commit/git commit --amend/".
> 
> One workaround might be to
> 
>     git reset --soft HEAD^
>     git status [<pathspec>]
>     ...
>     git commit -c @{1}
> 
> but that is simply too error prone and ugly.  I would say it would
> be better if "status" knows how to answer that "I am planning to
> conclude with 'git commit --amend'" question.
> 
> The reason why I am torn is because I do not think "status --amend"
> is a sensible name for that option.  "status" is not about amending
> anything.
> 
> If the normal "status" is "give me status for the next commit", this
> new mode would be "give me status for the 'commit --amend'".  Naming
> it "git status --for-amend" crossed my mind, but it does not sound
> great to me, either.
> 
> So...

I think I can understand some of the "feeling torn" aspects.

I know exactly the problem that "status --amend" is trying to
solve, as it is non-trivial to get the status bits correct
for "what it looks like when amending a commit".

git-gui and git-cola both do some clever things to make their
amend modes work smoothly for the user, and having something
like "status --amend" could have made the implementation
simpler.

But "status --amend" still makes me torn too because it's too
special-purpose.  Taking a step back, "status" gives you a lot
of information, and all of it is relative to HEAD.

"status --amend" is really asking to make it all relative to
HEAD^ instead.

So I wonder, would the syntax not be more gittish if it were,

	git status HEAD
	git status HEAD^
	git status <ref> -- <pathspec>

and it'll compare your repo's status relative to any ref.

I like the above because it's general and not hard-wired into
the concept of amending a commit, but it enables that use case
as well.

The ultimate convenience for script writers would be if this
command gracefully handled the edge cases.  I have a separate
code path for this one, and eliminating it would be awesome.

"git init" time, where no commit exists (and thus "git status
HEAD|HEAD^" makes no sense) is an inconvenience to script
around. The most convenient behavior for the user would be to
treat that situation as being equivalent to comparing against an
empty tree.

That could extend to post-"git init" when a single commit exists
and the user asks for "git status HEAD^" for amending purposes.
It'd be great if the tool was dwim enough to also treat that as
an empty tree comparison.

I don't know if that's going too far, because normally git
would just yell, "HEAD^ makes no sense!" and tell the user to
bugger off, but I can definitely see the utility in a dwimmy
soft-edges status tool that papers over some of these edge
cases.

Would generalizing "status" to have a more gittish syntax make
you feel less torn?
-- 
David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-04-01  8:43     ` David Aguilar
@ 2015-04-01 17:16       ` Junio C Hamano
  2015-04-03 21:57         ` David Aguilar
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2015-04-01 17:16 UTC (permalink / raw)
  To: David Aguilar; +Cc: Jeff King, Sven Strickroth, git

David Aguilar <davvid@gmail.com> writes:

> Would generalizing "status" to have a more gittish syntax make
> you feel less torn?

One of my early draft responses included a one whose punch line was
"Why limit the comparison to HEAD and HEAD^ but no other point of
reference?"

But I discarded it as a useless suggestion before writing it down,
primarily because I couldn't come up with an explanation _why_ being
able to say "git status --relative-to=next Makefile" is useful when
on the 'master' branch.

Surely, I may have changes in the Makefile relative to my index
because I am preparing for the next rc release, and the Makefile in
the index may be different from that of the 'next' branch because I
am on my 'master' branch.  The potential output can be "explained"
in such a mechanical sense (e.g. "we generated the output this
way").

But I do not see an easy-to-understand explanation of the _meaning_
of the output, i.e. "What does it mean that the working tree file
has been modified since the checkout and the index is different
relative to that other branch?  How does that information help me
after I learn it?  What would I do differently with that information
at hand?"

Compared to that, "Show me what damage I would inflict if I did
'commit' now.  By the way, I may want to see that information
limited to these paths" is a question whose utility is easily
explained, and so is the same question with 'commit' replaced by
'commit --amend'.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-04-01 17:16       ` Junio C Hamano
@ 2015-04-03 21:57         ` David Aguilar
  2015-04-03 22:05           ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: David Aguilar @ 2015-04-03 21:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Sven Strickroth, git

On Wed, Apr 01, 2015 at 10:16:22AM -0700, Junio C Hamano wrote:
> David Aguilar <davvid@gmail.com> writes:
> 
> > Would generalizing "status" to have a more gittish syntax make
> > you feel less torn?
> 
> One of my early draft responses included a one whose punch line was
> "Why limit the comparison to HEAD and HEAD^ but no other point of
> reference?"
> 
> But I discarded it as a useless suggestion before writing it down,
> primarily because I couldn't come up with an explanation _why_ being
> able to say "git status --relative-to=next Makefile" is useful when
> on the 'master' branch.


Aesthetically it's appealing because it mirrors commands like
"git diff HEAD^", etc.

I can see it being useful for script writers but it's a minority
case that's already handled by having "status --amend" for the
common case of needing to mimic "commit --amend".

Beyond that use case, someone could use it to write a butchery
tool that gets a quick high-level diff of changes for both index
and worktree against an arbitrary ref, and then apply those
changes selectively using other git tools.

status is superior to the other tools (diff-index, diff-files,
ls-files) because we can get all of the information in a single
git invocation, which is more of a perf. concern but worth
considering.

> Surely, I may have changes in the Makefile relative to my index
> because I am preparing for the next rc release, and the Makefile in
> the index may be different from that of the 'next' branch because I
> am on my 'master' branch.  The potential output can be "explained"
> in such a mechanical sense (e.g. "we generated the output this
> way").
> 
> But I do not see an easy-to-understand explanation of the _meaning_
> of the output, i.e. "What does it mean that the working tree file
> has been modified since the checkout and the index is different
> relative to that other branch?  How does that information help me
> after I learn it?  What would I do differently with that information
> at hand?"
> 
> Compared to that, "Show me what damage I would inflict if I did
> 'commit' now.  By the way, I may want to see that information
> limited to these paths" is a question whose utility is easily
> explained, and so is the same question with 'commit' replaced by
> 'commit --amend'.

Yeah, ergonomically it would still make sense to have
"status --amend" (even if it also were to also understand
"status <ref>") for symmetry.
-- 
David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: RFC: git status --amend
  2015-04-03 21:57         ` David Aguilar
@ 2015-04-03 22:05           ` Jeff King
  0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2015-04-03 22:05 UTC (permalink / raw)
  To: David Aguilar; +Cc: Junio C Hamano, Sven Strickroth, git

On Fri, Apr 03, 2015 at 02:57:48PM -0700, David Aguilar wrote:

> > But I discarded it as a useless suggestion before writing it down,
> > primarily because I couldn't come up with an explanation _why_ being
> > able to say "git status --relative-to=next Makefile" is useful when
> > on the 'master' branch.
> 
> Aesthetically it's appealing because it mirrors commands like
> "git diff HEAD^", etc.
> 
> I can see it being useful for script writers but it's a minority
> case that's already handled by having "status --amend" for the
> common case of needing to mimic "commit --amend".
> 
> Beyond that use case, someone could use it to write a butchery
> tool that gets a quick high-level diff of changes for both index
> and worktree against an arbitrary ref, and then apply those
> changes selectively using other git tools.

Hmm. What if you had a tool that created commits out of an alternate
working tree and index, and then committed directly to a branch without
touching HEAD? Then you might run:

  GIT_WORK_TREE=... GIT_INDEX_FILE=... git status --relative-to=mybranch

right before running:

  old=$(git rev-parse refs/heads/mybranch) &&
  tree=$(GIT_INDEX_FILE=... git commit-tree) &&
  commit=$(echo whatever | git commit-tree -p $old $tree) &&
  git update-ref refs/heads/mybranch $old

or similar. That is basically "git-new-workdir", but with no per-workdir
HEAD. Which is probably crazy, but maybe useful for a one-off commit to
another branch or something.

I dunno. I do not have such a tool or plan to work on one, but it is at
least plausible to me.

-Peff

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-04-03 22:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-31 14:59 RFC: git status --amend Sven Strickroth
2015-03-31 18:04 ` Jeff King
2015-03-31 18:35   ` Junio C Hamano
2015-04-01  8:43     ` David Aguilar
2015-04-01 17:16       ` Junio C Hamano
2015-04-03 21:57         ` David Aguilar
2015-04-03 22:05           ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.