git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 0/3] Git commit --patch (again)

From
Jeff King <peff@peff.net>
Date
May 9, 2011, 14:44 UTC
Message-ID
<20110509144451.GA11362@sigill.intra.peff.net>
In-Reply-To
<1304748001-17982-1-git-send-email-conrad.irwin@gmail.com>
On Fri, May 06, 2011 at 10:59:58PM -0700, conrad.irwin@gmail.com wrote:
> I've rebased my support for git commit -p onto the current master
> branch. I've posted it to the list twice before [1][2].

Thanks for reposting. I had been meaning to look at this again, but hadn't gotten around to it. So thanks for being persistent. :)

>   Use a temporary index for git commit --interactive

I think the intent of this one is good. In reviewing your initial series, I had wondered about consistency with respect to the atomicity of "git commit -p" versus "git add -p" (i.e., what state is the index left in when you abort). But reading through the discussion again, I think we should worry more about consistency between "git commit -i" and "git commit --interactive". That is, both should produce no changes to the index when the commit is aborted. So I think your patch is a step in the right direction.

That still leaves an inconsistency in "git add -p" versus "git commit -p" (e.g., if you abort "git add -p" with "^C"). But if we care, the right solution is probably to make "git add -p" atomic. That can be a separate topic, though, and I'm not sure anyone really cares enough to work on it.

I have one final question. If I do abort a commit, is there any way to recover the state that was in the temporary index? That is, if I abort "git commit -i" by using an empty commit message, it is easy enough to use shell history to repeat the command (possibly with a different set of files). But if I spend some time selecting (and possibly editing) hunks, and then decide to abort the commit, is there any way to recover the intermediate index state?

>From my reading of the code, it looks like "no". We will rollback the
lockfile which contains the new index when aborting the commit.

I'm not sure if it is worth caring about. If you are really interested in index state, you are probably better off using "git add -p" and "git commit" separately. And even if we kept the index file around, it requires a fairly savvy plumbing user to be able to pick changes out of it.

>   Allow git commit --interactive with paths

Hmm. Test t7501.8 explicitly tests that this isn't allowed. But the test is poorly written, and falsely returns success even with your patch.

The original test should have looked like this:
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 7f7f7c7..8090b3c 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -45,7 +45,8 @@ test_expect_success \
 test_expect_success PERL \
 	"using paths with --interactive" \
 	"echo bong-o-bong >file &&
-	! (echo 7 | git commit -m foo --interactive file)"
+	! ({ echo 2; echo 1; echo; echo 7; } |
+	git commit -m foo --interactive file)"
 
 test_expect_success \
 	"using invalid commit with -C" \

which does properly fail with your change. Your commit should tweak that
test (speaking of which, it would be nice for patch 1 to have a test,
too).

Other than that, the code in all 3 looks fine to me.

-Peff
Previous: Sverre RabbelierNext: Junio C Hamano
Message 11 of 21 in “Git commit --patch (again)”
  1. 0/3 Git commit --patch (again)conrad.irwin@gmail.com, May 7, 2011
  2. 1/3 Use a temporary index for git commit --interactiveconrad.irwin@gmail.com, May 7, 2011
  3. 2/3 Allow git commit --interactive with pathsconrad.irwin@gmail.com, May 7, 2011
  4. 3/3 Add support for -p/--patch to git-commitconrad.irwin@gmail.com, May 7, 2011
  5. Valentin HaenelMay 7, 2011
  6. Conrad IrwinMay 7, 2011
  7. 3/3 Add support for -p/--patch to git-commitConrad Irwin, May 7, 2011
  8. Junio C HamanoMay 8, 2011
  9. Add commit to list of config.singlekey commandsConrad Irwin, May 7, 2011
  10. Sverre RabbelierMay 7, 2011
  11. Jeff KingMay 9, 2011
  12. Junio C HamanoMay 9, 2011
  13. Jeff KingMay 9, 2011
  14. Junio C HamanoMay 9, 2011
  15. Junio C HamanoMay 9, 2011
  16. Jeff KingMay 10, 2011
  17. Jeff KingMay 10, 2011
  18. Conrad IrwinMay 10, 2011
  19. Test atomic git-commit --interactiveConrad Irwin, May 10, 2011
  20. Jeff KingMay 10, 2011
  21. Conrad IrwinMay 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.