git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git alias question
@ 2011-12-29  1:27 Michael Horowitz
  2011-12-29  3:21 ` Miles Bader
  2011-12-29 17:08 ` Dave Borowitz
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Horowitz @ 2011-12-29  1:27 UTC (permalink / raw)
  To: git

Hello all,

I have been unable to find a solution to this, so I figured I would
post to this list...

I am trying to make an easy command to let me look at the last diff to
a specified file, either plain or with a diff tool, such as vimdiff.
This is the last actual change, not just HEAD^, because the file may
not have changed in many commits.

I was able to make the following 2 aliases, which work perfectly
except for one problem...

ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

The problem is the limitation that shell commands are always executed
at the top-level directory of the repository.  Normally I am in a
deeply nested directory, so if I specify the file name in that
directory, it doesn't work.  Having to specify the full path relative
to the top level makes these aliases more cumbersome to use than their
worth.

Is there a way to get around this, or even a completely different way
to do this that I am missing?  I want to avoid making a completely
separate shell script.

Thanks,

Mike

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

* Re: git alias question
  2011-12-29  1:27 git alias question Michael Horowitz
@ 2011-12-29  3:21 ` Miles Bader
  2011-12-29  5:32   ` Junio C Hamano
  2011-12-29 17:08 ` Dave Borowitz
  1 sibling, 1 reply; 8+ messages in thread
From: Miles Bader @ 2011-12-29  3:21 UTC (permalink / raw)
  To: Michael Horowitz; +Cc: git

Michael Horowitz <michael.horowitz@ieee.org> writes:
> I was able to make the following 2 aliases, which work perfectly
> except for one problem...
>
> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> The problem is the limitation that shell commands are always executed
> at the top-level directory of the repository.

Hmmm, it'd be cool if git exported an environment variable containing
the CWD when it invoked external aliases like this...!

-Miles

-- 
Love is the difficult realization that something other than oneself is real.
[Iris Murdoch]

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

* Re: git alias question
  2011-12-29  3:21 ` Miles Bader
@ 2011-12-29  5:32   ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2011-12-29  5:32 UTC (permalink / raw)
  To: Miles Bader; +Cc: Michael Horowitz, git

Miles Bader <miles@gnu.org> writes:

> Michael Horowitz <michael.horowitz@ieee.org> writes:
>> I was able to make the following 2 aliases, which work perfectly
>> except for one problem...
>>
>> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>>
>> The problem is the limitation that shell commands are always executed
>> at the top-level directory of the repository.
>
> Hmmm, it'd be cool if git exported an environment variable containing
> the CWD when it invoked external aliases like this...!

Yeah, something like GIT_PREFIX environment variable, I guess.

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

* Re: git alias question
  2011-12-29  1:27 git alias question Michael Horowitz
  2011-12-29  3:21 ` Miles Bader
@ 2011-12-29 17:08 ` Dave Borowitz
  2011-12-30  1:59   ` David Aguilar
  1 sibling, 1 reply; 8+ messages in thread
From: Dave Borowitz @ 2011-12-29 17:08 UTC (permalink / raw)
  To: Michael Horowitz; +Cc: git

On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
<michael.horowitz@ieee.org> wrote:
> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

FWIW, you can also do this as:
  ldiff = log -p -1 --format=format: --

> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

I don't know that you can do something equivalent with difftool. I
suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
wrapper> git ldiff", but that's not very helpful.

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

* Re: git alias question
  2011-12-29 17:08 ` Dave Borowitz
@ 2011-12-30  1:59   ` David Aguilar
  2011-12-31 21:31     ` Michael Horowitz
  0 siblings, 1 reply; 8+ messages in thread
From: David Aguilar @ 2011-12-30  1:59 UTC (permalink / raw)
  To: Dave Borowitz; +Cc: Michael Horowitz, git, Junio C Hamano

On Thu, Dec 29, 2011 at 9:08 AM, Dave Borowitz <dborowitz@google.com> wrote:
> On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
> <michael.horowitz@ieee.org> wrote:
>> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> FWIW, you can also do this as:
>  ldiff = log -p -1 --format=format: --
>
>> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> I don't know that you can do something equivalent with difftool. I
> suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
> wrapper> git ldiff", but that's not very helpful.

difftool cannot be driven by log right now.  It is something we
thought would be helpful in the past:

http://thread.gmane.org/gmane.comp.version-control.git/114269/focus=114367

On 2009-03-23 Junio C Hamano <gitster <at> pobox.com> wrote:
> Perhaps we would want a convenient way for "log -p" or "show -p" to drive
> difftool as a backend?

I think that's exactly it.  difftool wraps diff; a log equivalent
would be quite helpful.

One idea is for difftool to learn a "--log" option to make it wrap log
instead.  I don't know if a diff-like command having a "--log" option
is ideal from a consistency-of-user-interface POV so I'm open to
ideas.  It is convenient, though.  It does seem like difftool would be
a good place to expose this feature.

I'd be interested in the "teach log / show -p about GIT_EXTERNAL_DIFF"
route, if that sounds like a good idea.
-- 
            David

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

* Re: git alias question
  2011-12-30  1:59   ` David Aguilar
@ 2011-12-31 21:31     ` Michael Horowitz
  2011-12-31 23:30       ` Jakub Narebski
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Horowitz @ 2011-12-31 21:31 UTC (permalink / raw)
  To: David Aguilar; +Cc: Dave Borowitz, git, Junio C Hamano

The log operation does seem to make the most sense as the mechanism to
search for the results.  Making it work with difftool would work...
Not sure if "--log" to difftool or some other options as suggested in
the other thread would be most consistent UI-wise as stated, but
either would work for me.

On a separate note, some environment variable like GIT_PREFIX with the
CWD would make the alias functionality more flexible.

Mike

On Thu, Dec 29, 2011 at 8:59 PM, David Aguilar <davvid@gmail.com> wrote:
>
> On Thu, Dec 29, 2011 at 9:08 AM, Dave Borowitz <dborowitz@google.com> wrote:
> > On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
> > <michael.horowitz@ieee.org> wrote:
> >> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> >
> > FWIW, you can also do this as:
> >  ldiff = log -p -1 --format=format: --
> >
> >> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> >
> > I don't know that you can do something equivalent with difftool. I
> > suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
> > wrapper> git ldiff", but that's not very helpful.
>
> difftool cannot be driven by log right now.  It is something we
> thought would be helpful in the past:
>
> http://thread.gmane.org/gmane.comp.version-control.git/114269/focus=114367
>
> On 2009-03-23 Junio C Hamano <gitster <at> pobox.com> wrote:
> > Perhaps we would want a convenient way for "log -p" or "show -p" to drive
> > difftool as a backend?
>
> I think that's exactly it.  difftool wraps diff; a log equivalent
> would be quite helpful.
>
> One idea is for difftool to learn a "--log" option to make it wrap log
> instead.  I don't know if a diff-like command having a "--log" option
> is ideal from a consistency-of-user-interface POV so I'm open to
> ideas.  It is convenient, though.  It does seem like difftool would be
> a good place to expose this feature.
>
> I'd be interested in the "teach log / show -p about GIT_EXTERNAL_DIFF"
> route, if that sounds like a good idea.
> --
>             David

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

* Re: git alias question
  2011-12-31 21:31     ` Michael Horowitz
@ 2011-12-31 23:30       ` Jakub Narebski
  2012-01-02  5:57         ` Michael Horowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2011-12-31 23:30 UTC (permalink / raw)
  To: Michael Horowitz; +Cc: David Aguilar, Dave Borowitz, git, Junio C Hamano

Michael Horowitz <michael.horowitz@ieee.org> writes:

> The log operation does seem to make the most sense as the mechanism to
> search for the results.  Making it work with difftool would work...
> Not sure if "--log" to difftool or some other options as suggested in
> the other thread would be most consistent UI-wise as stated, but
> either would work for me.
> 
> On a separate note, some environment variable like GIT_PREFIX with the
> CWD would make the alias functionality more flexible.

1f5d271 (setup: Provide GIT_PREFIX to built-ins, 2011-05-25) is
present in v1.7.7; 7cf16a1 (handle_alias: provide GIT_PREFIX to
!alias, 2011-04-27) is in 1.7.6

-- 
Jakub Narebski

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

* Re: git alias question
  2011-12-31 23:30       ` Jakub Narebski
@ 2012-01-02  5:57         ` Michael Horowitz
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Horowitz @ 2012-01-02  5:57 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: David Aguilar, Dave Borowitz, git, Junio C Hamano

Nice, works perfectly!  Didn't notice that was there, guess last time
I looked, I was using an older version.  I see it is in the git config
man page and all now.

Thanks,

Mike



On Sat, Dec 31, 2011 at 6:30 PM, Jakub Narebski <jnareb@gmail.com> wrote:
>
> Michael Horowitz <michael.horowitz@ieee.org> writes:
>
> > The log operation does seem to make the most sense as the mechanism to
> > search for the results.  Making it work with difftool would work...
> > Not sure if "--log" to difftool or some other options as suggested in
> > the other thread would be most consistent UI-wise as stated, but
> > either would work for me.
> >
> > On a separate note, some environment variable like GIT_PREFIX with the
> > CWD would make the alias functionality more flexible.
>
> 1f5d271 (setup: Provide GIT_PREFIX to built-ins, 2011-05-25) is
> present in v1.7.7; 7cf16a1 (handle_alias: provide GIT_PREFIX to
> !alias, 2011-04-27) is in 1.7.6
>
> --
> Jakub Narebski

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

end of thread, other threads:[~2012-01-02  5:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-29  1:27 git alias question Michael Horowitz
2011-12-29  3:21 ` Miles Bader
2011-12-29  5:32   ` Junio C Hamano
2011-12-29 17:08 ` Dave Borowitz
2011-12-30  1:59   ` David Aguilar
2011-12-31 21:31     ` Michael Horowitz
2011-12-31 23:30       ` Jakub Narebski
2012-01-02  5:57         ` Michael Horowitz

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 NNTP newsgroup(s).