Skip to contentSkip to conversation

git-walkthrough-add script

DISCUSSION William Morgan 5 participants 16 messages Jun 15, 2016

lore
Share & tools
lore
#1 lore raw
Quoted 5 lines · William Morgan

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

#2 lore raw

Excerpts from Jeff King's message of Thu Jan 03 23:26:50 -0800 2008:

Quoted 4 lines

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.

Quoted 1 line

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

Signature · 1 line
William <[email protected]>
#3 lore raw
Quoted 4 lines · William Morgan
Quoted 1 line

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

#4 lore raw

Excerpts from Jeff King's message of Fri Jan 04 13:07:51 -0800 2008:

Quoted 3 lines

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.

Signature · 1 line
William <[email protected]>
#5 lore raw
Quoted 8 lines · William Morgan

Excerpts from Jeff King's message of Fri Jan 04 13:07:51 -0800 2008:

Quoted 3 lines

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.

#6 lore raw
Quoted 16 lines · Junio C Hamano

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" .
Quoted 2 lines
    +
    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,

Signature · 4 lines
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [email protected]
Use XMPP!
#7 lore raw
In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · William Morgan

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?

#8 lore raw

Excerpts from Junio C Hamano's message of Fri Jan 04 18:55:41 -0800 2008:

Quoted 3 lines

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!

Signature · 1 line
William <[email protected]>
#9 lore raw
In reply to William Morgan

Hi,

Quoted 5 lines · William Morgan

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,

Signature · 4 lines
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [email protected]
Use XMPP!
#10 lore raw

Excerpts from Pedro Melo's message of Fri Jan 04 15:26:41 -0800 2008:

Quoted 1 line

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?

Signature · 1 line
William <[email protected]>
#11 lore raw

Hi,

Quoted 9 lines · William Morgan

Excerpts from Pedro Melo's message of Fri Jan 04 15:26:41 -0800 2008:

Quoted 1 line

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

a +3 -0
index b6b8cab..456bb2d 100644
@@ -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

Signature · 4 lines
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: [email protected]
Use XMPP!
#12 lore raw
In reply to Pedro Melo
Quoted 3 lines · Pedro Melo

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

#13 lore raw

Excerpts from Miklos Vajna's message of Fri Jan 04 17:00:11 -0800 2008:

Quoted 3 lines

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

Signature · 1 line
William <[email protected]>
#14 lore raw
Quoted 1 line · William Morgan

Also, mine has color support. :)

On the current master, try:

git config color.interactive auto
git config color.diff auto
git add -i

-Peff

#15 lore raw
In reply to Pedro Melo
Quoted 3 lines · Pedro Melo

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