# git-walkthrough-add script

16 messages from 2008-01-04 to 2008-01-05. Participants: William Morgan, Jeff King, Pedro Melo, Junio C Hamano, Miklos Vajna.
Thread: https://gitlist.dev/t/11463

## William Morgan, 2008-01-04 06:14

Subject: git-walkthrough-add script
Message-ID: <1199426431-sup-6092@south>
URL: https://gitlist.dev/e/1199426431-sup-6092%40south

```
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, 2008-01-04 07:26

Subject: Re: git-walkthrough-add script
Message-ID: <20080104072650.GA24685@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080104072650.GA24685%40coredump.intra.peff.net
In-Reply-To: <1199426431-sup-6092@south>

```
On Thu, Jan 03, 2008 at 10:14:31PM -0800, William Morgan wrote:

> 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, 2008-01-04 18:31

Subject: Re: git-walkthrough-add script
Message-ID: <1199471454-sup-4786@south>
URL: https://gitlist.dev/e/1199471454-sup-4786%40south
In-Reply-To: <20080104072650.GA24685@coredump.intra.peff.net>

```
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, 2008-01-04 21:07

Subject: Re: git-walkthrough-add script
Message-ID: <20080104210751.GB26248@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080104210751.GB26248%40coredump.intra.peff.net
In-Reply-To: <1199471454-sup-4786@south>

```
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

```

## Pedro Melo, 2008-01-04 23:26

Subject: Re: git-walkthrough-add script
Message-ID: <2CC98B8C-CBB1-4C26-8C94-B152A4D02DDC@simplicidade.org>
URL: https://gitlist.dev/e/2CC98B8C-CBB1-4C26-8C94-B152A4D02DDC%40simplicidade.org
In-Reply-To: <1199426431-sup-6092@south>

```
Hi,

On Jan 4, 2008, at 6:14 AM, William Morgan wrote:

> 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, 2008-01-04 23:28

Subject: Re: git-walkthrough-add script
Message-ID: <7vd4shi31o.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd4shi31o.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <2CC98B8C-CBB1-4C26-8C94-B152A4D02DDC@simplicidade.org>

```
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, 2008-01-05 00:02

Subject: Re: git-walkthrough-add script
Message-ID: <1199491057-sup-5588@south>
URL: https://gitlist.dev/e/1199491057-sup-5588%40south
In-Reply-To: <2CC98B8C-CBB1-4C26-8C94-B152A4D02DDC@simplicidade.org>

```
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, 2008-01-05 00:17

Subject: Re: git-walkthrough-add script
Message-ID: <8666B7CA-D47F-40A0-88A2-3756C0663296@simplicidade.org>
URL: https://gitlist.dev/e/8666B7CA-D47F-40A0-88A2-3756C0663296%40simplicidade.org
In-Reply-To: <1199491057-sup-5588@south>

```
Hi,

On Jan 5, 2008, at 12:02 AM, William Morgan wrote:
> 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, 2008-01-05 01:00

Subject: Re: git-walkthrough-add script
Message-ID: <20080105010011.GV29972@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080105010011.GV29972%40genesis.frugalware.org
In-Reply-To: <2CC98B8C-CBB1-4C26-8C94-B152A4D02DDC@simplicidade.org>

```
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, 2008-01-05 02:37

Subject: Re: git-walkthrough-add script
Message-ID: <1199500441-sup-4067@south>
URL: https://gitlist.dev/e/1199500441-sup-4067%40south
In-Reply-To: <20080104210751.GB26248@coredump.intra.peff.net>

```
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, 2008-01-05 02:50

Subject: Re: git-walkthrough-add script
Message-ID: <7vprwhf0kf.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vprwhf0kf.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1199500441-sup-4067@south>

```
William Morgan <wmorgan-git@masanjin.net> writes:

> 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.

```

## William Morgan, 2008-01-05 02:54

Subject: Re: git-walkthrough-add script
Message-ID: <1199500828-sup-502@south>
URL: https://gitlist.dev/e/1199500828-sup-502%40south
In-Reply-To: <20080105010011.GV29972@genesis.frugalware.org>

```
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>

```

## Junio C Hamano, 2008-01-05 02:55

Subject: Re: git-walkthrough-add script
Message-ID: <7vlk75f0b6.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vlk75f0b6.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <7vprwhf0kf.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> 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, 2008-01-05 03:02

Subject: Re: git-walkthrough-add script
Message-ID: <1199502089-sup-447@south>
URL: https://gitlist.dev/e/1199502089-sup-447%40south
In-Reply-To: <7vlk75f0b6.fsf@gitster.siamese.dyndns.org>

```
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>

```

## Jeff King, 2008-01-05 03:43

Subject: Re: git-walkthrough-add script
Message-ID: <20080105034355.GA26892@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080105034355.GA26892%40coredump.intra.peff.net
In-Reply-To: <1199500828-sup-502@south>

```
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

```

## Pedro Melo, 2008-01-05 04:08

Subject: Re: git-walkthrough-add script
Message-ID: <0F790B89-2FFB-4C54-A109-E55E1FB57D3B@simplicidade.org>
URL: https://gitlist.dev/e/0F790B89-2FFB-4C54-A109-E55E1FB57D3B%40simplicidade.org
In-Reply-To: <7vprwhf0kf.fsf@gitster.siamese.dyndns.org>

```

On Jan 5, 2008, at 2:50 AM, Junio C Hamano wrote:
> 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!

```
