threads / discuss / 11463

git-walkthrough-add script

Subject: git-walkthrough-add script

## tl;dr

16 messages between Jan 4, 2008 and Jan 5, 2008.

replies: 15people: 5as markdown or json

William Morgan· Jan 4, 2008, 06:14 UTC · lore
Hi all,

I've written a little script to do darcs-style hunk-by-hunk walkthroughs. It's based on the git-hunk-commit script that was floating around. Maybe someone else will find it useful.

http://git-wt-commit.rubyforge.org/
-- 
William <wmorgan-git@masanjin.net>
Jeff King· Jan 4, 2008, 07:26 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

On Thu, Jan 03, 2008 at 10:14:31PM -0800, William Morgan wrote:
Show 5 quoted lines
> I've written a little script to do darcs-style hunk-by-hunk
> walkthroughs. It's based on the git-hunk-commit script that was floating
> around. Maybe someone else will find it useful.
> 
> http://git-wt-commit.rubyforge.org/

It didn't work for me, since the diff parsing failed to match my particular colors (I needed /^.....diff/ instead of /^....diff/). I suspect the color matching needs to be more flexible to be generally useful.

However, I'm not clear what advantages this has over "git add -p".
-Peff
William Morgan· Jan 4, 2008, 18:31 UTC · re: Jeff King · lore

Re: git-walkthrough-add script

Excerpts from Jeff King's message of Thu Jan 03 23:26:50 -0800 2008:
> It didn't work for me, since the diff parsing failed to match my
> particular colors (I needed /^.....diff/ instead of /^....diff/). I
> suspect the color matching needs to be more flexible to be generally
> useful.
Fixed, thanks.
> However, I'm not clear what advantages this has over "git add -p".

A better interface. (Where by "better", I mean, behaves how I personally prefer.)

-- 
William <wmorgan-git@masanjin.net>
Jeff King· Jan 4, 2008, 21:07 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

On Fri, Jan 04, 2008 at 10:31:03AM -0800, William Morgan wrote:
> > However, I'm not clear what advantages this has over "git add -p".
> 
> A better interface. (Where by "better", I mean, behaves how I personally
> prefer.)

OK. If it works for you, then I'm not one to say you shouldn't use it. But if you have interface improvement suggestions for "git-add -i" or "git-add -p", I'm sure they would be well-received (post-1.5.4 release, of course).

-Peff
William Morgan· Jan 5, 2008, 02:37 UTC · re: Jeff King · lore

Re: git-walkthrough-add script

Excerpts from Jeff King's message of Fri Jan 04 13:07:51 -0800 2008:
> But if you have interface improvement suggestions for "git-add -i" or
> "git-add -p", I'm sure they would be well-received (post-1.5.4
> release, of course).

Not to show off my git newbness any more than necessary, but when I run both git-add -i and git-add -p, I see exactly the same output and interface. Are they meant to be different? This is with both master and next branches of the git repo.

  ~/devel/sup$ ~/devel/git/installed/bin/git-add -i
             staged     unstaged path
    1:    unchanged        +1/-0 doc/TODO
    2:    unchanged        +1/-1 lib/sup/message.rb
    3:    unchanged      +28/-43 lib/sup/thread.rb
  
  *** Commands ***
    1: status       2: update       3: revert       4: add untracked
    5: patch        6: diff         7: quit         8: help
  What now> 
  Bye.
  ~/devel/sup$ ~/devel/git/installed/bin/git-add -p
             staged     unstaged path
    1:    unchanged        +1/-0 doc/TODO
    2:    unchanged        +1/-1 lib/sup/message.rb
    3:    unchanged      +28/-43 lib/sup/thread.rb
  
  *** Commands ***
    1: status       2: update       3: revert       4: add untracked
    5: patch        6: diff         7: quit         8: help
  What now> 
  Bye.
-- 
William <wmorgan-git@masanjin.net>
Junio C Hamano· Jan 5, 2008, 02:50 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

William Morgan <wmorgan-git@masanjin.net> writes:
Show 8 quoted lines
> Excerpts from Jeff King's message of Fri Jan 04 13:07:51 -0800 2008:
>> But if you have interface improvement suggestions for "git-add -i" or
>> "git-add -p", I'm sure they would be well-received (post-1.5.4
>> release, of course).
>
> Not to show off my git newbness any more than necessary, but when I run
> both git-add -i and git-add -p, I see exactly the same output and
> interface. Are they meant to be different?
They are meant to be different.
    $ git reset --hard
    $ echo >>Makefile
    $ echo >>psql/Makefile
    $ git add -p
    diff --git a/Makefile b/Makefile
    index a2177bc..eb250b0 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -54,3 +54,4 @@ snapdiff ::
            latest=`ls -1dr $(_snap)/release-????-??-?? | head -n 1` &&
            \
            diff -X dontdiff -ru "$$latest" .
    +
    Stage this hunk [y/n/a/d/?]? ^C
    $ git add -i
               staged     unstaged path
      1:    unchanged        +1/-0 Makefile
      2:    unchanged        +1/-0 psql/Makefile
    *** Commands ***
      1: [s]tatus     2: [u]pdate     3: [r]evert     4: [a]dd
      untracked
      5: [p]atch      6: [d]iff       7: [q]uit       8: [h]elp
    What now> ^C
There may be something broken with your git installation.
Junio C Hamano· Jan 5, 2008, 02:55 UTC · re: Junio C Hamano · lore

Re: git-walkthrough-add script

Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> William Morgan <wmorgan-git@masanjin.net> writes:
>
>> Not to show off my git newbness any more than necessary, but when I run
>> both git-add -i and git-add -p, I see exactly the same output and
>> interface. Are they meant to be different?
>
> They are meant to be different.
> ...
> There may be something broken with your git installation.

A shot in the dark. Do you have more than one installation of git, one of which is ancient and whose git-add--interactive does not even have --patch option?

William Morgan· Jan 5, 2008, 03:02 UTC · re: Junio C Hamano · lore

Re: git-walkthrough-add script

Excerpts from Junio C Hamano's message of Fri Jan 04 18:55:41 -0800 2008:
> A shot in the dark.  Do you have more than one installation of git,
> one of which is ancient and whose git-add--interactive does not even
> have --patch option?
Precisely. Now I finally see what you were talking about.

Well, yup, this is pretty much what I had in mind. If only I had known. Guess I'll throw away my script now!

-- 
William <wmorgan-git@masanjin.net>
Pedro Melo· Jan 5, 2008, 04:08 UTC · re: Junio C Hamano · lore

Re: git-walkthrough-add script

On Jan 5, 2008, at 2:50 AM, Junio C Hamano wrote:
Show 18 quoted lines
> They are meant to be different.
>
>     $ git reset --hard
>     $ echo >>Makefile
>     $ echo >>psql/Makefile
>     $ git add -p
>     diff --git a/Makefile b/Makefile
>     index a2177bc..eb250b0 100644
>     --- a/Makefile
>     +++ b/Makefile
>     @@ -54,3 +54,4 @@ snapdiff ::
>             latest=`ls -1dr $(_snap)/release-????-??-?? | head -n  
> 1` &&
>             \
>             diff -X dontdiff -ru "$$latest" .
>
>     +
>     Stage this hunk [y/n/a/d/?]? ^C
BTW, I'm using 1.5.4rc2 and this prompt shows:
Stage this hunk [y/n/a/d/j/J/?]?
but the help (after you press ?) also mentions:

k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks

but those three options don't seem to work.
Best regards,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo@simplicidade.org
Use XMPP!
Pedro Melo· Jan 4, 2008, 23:26 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

Hi,
On Jan 4, 2008, at 6:14 AM, William Morgan wrote:
Show 6 quoted lines
> I've written a little script to do darcs-style hunk-by-hunk
> walkthroughs. It's based on the git-hunk-commit script that was  
> floating
> around. Maybe someone else will find it useful.
>
> http://git-wt-commit.rubyforge.org/

Maybe I'm doing something wrong, but comparing git-add -p with your script, git-add -p is more darcs'ish. With git-add, if I have several changes in the same file, I get to choose per hunk.

You script asks me to add all the changes in the same file at once.
Best regards,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo@simplicidade.org
Use XMPP!
Junio C Hamano· Jan 4, 2008, 23:28 UTC · re: Pedro Melo · lore

Re: git-walkthrough-add script

Pedro Melo <melo@simplicidade.org> writes:
> Maybe I'm doing something wrong, but comparing git-add -p with your
> script, git-add -p is more darcs'ish. With git-add, if I have several
> changes in the same file, I get to choose per hunk.

Heh, thanks from somebody who did "add -i" who admits he used darcs for a few months ;-).

William Morgan· Jan 5, 2008, 00:02 UTC · re: Pedro Melo · lore

Re: git-walkthrough-add script

Excerpts from Pedro Melo's message of Fri Jan 04 15:26:41 -0800 2008:
> You script asks me to add all the changes in the same file at once.

It shouldn't. The whole point is to walk through and allow selection on a per-hunk basis.

Maybe I'm parsing the output of git diff incorrectly and not picking up hunk boundaries? Would you mind sending the output of a git diff that results in this behavior?

-- 
William <wmorgan-git@masanjin.net>
Pedro Melo· Jan 5, 2008, 00:17 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

Hi,
On Jan 5, 2008, at 12:02 AM, William Morgan wrote:
Show 11 quoted lines
> Excerpts from Pedro Melo's message of Fri Jan 04 15:26:41 -0800 2008:
>> You script asks me to add all the changes in the same file at once.
>
> It shouldn't. The whole point is to walk through and allow  
> selection on
> a per-hunk basis.
>
> Maybe I'm parsing the output of git diff incorrectly and not  
> picking up
> hunk boundaries? Would you mind sending the output of a git diff that
> results in this behavior?
I used a new git repo, just to test your script.
The diff is:
------ snip
diff --git a/a b/a
index b6b8cab..456bb2d 100644
--- a/a
+++ b/a
@@ -1,4 +1,5 @@
  asasas
+****
  assas
  assas
  asas
@@ -37,6 +38,7 @@ asasas
  assas
  assas
  asas
+=fsdfsdfsadfasdfsad=

  asasas
  assas
@@ -46,5 +48,6 @@ asas
  asasas
  assas
  assas
+asdasdasdasda=DASD=AS=DA=SD=
  asas

------ snip

Best regards
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo@simplicidade.org
Use XMPP!
Miklos Vajna· Jan 5, 2008, 01:00 UTC · re: Pedro Melo · lore

Re: git-walkthrough-add script

On Fri, Jan 04, 2008 at 11:26:41PM +0000, Pedro Melo <melo@simplicidade.org> wrote:
> Maybe I'm doing something wrong, but comparing git-add -p with your script, 
> git-add -p is more darcs'ish. With git-add, if I have several changes in 
> the same file, I get to choose per hunk.

hm, if you want a darcs-like record interface.. darcs record asks you if you want to include a newly added file in a commit or not, git-walkthrough-add won't do so :s

you might want to have a look at dg record (http://git.frugalware.org/repos/pacman-tools/darcs-git.py) which does this for you.

- VMiklos
William Morgan· Jan 5, 2008, 02:54 UTC · re: Miklos Vajna · lore

Re: git-walkthrough-add script

Excerpts from Miklos Vajna's message of Fri Jan 04 17:00:11 -0800 2008:
> you might want to have a look at dg record
> (http://git.frugalware.org/repos/pacman-tools/darcs-git.py) which does
> this for you.

That's very similar. But I wasn't trying to mimick the darcs interface exactly, just steal the parts I liked. For example, I don't actually like being forced to commit immediately after staging some changes; often I like to git diff --cached first.

Also, mine has color support. :)
-- 
William <wmorgan-git@masanjin.net>
Jeff King· Jan 5, 2008, 03:43 UTC · re: William Morgan · lore

Re: git-walkthrough-add script

On Fri, Jan 04, 2008 at 06:54:02PM -0800, William Morgan wrote:
> Also, mine has color support. :)
On the current master, try:
  git config color.interactive auto
  git config color.diff auto
  git add -i
-Peff

← back to recent threads