{"thread":{"id":"43444","subject":"[PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","startedAt":"2006-11-30T13:24:04Z","lastAt":"2006-12-01T10:59:00Z","messageCount":7,"participants":["Andy Parkins","Salikh Zakirov","Nguyen Thai Ngoc Duy","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"297356","messageId":"200611301324.04993.andyparkins@gmail.com","threadId":"43444","inReplyTo":"ekmlar$ask$2@sea.gmane.org","subject":"[PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-11-30T13:24:04Z","receivedAt":"2006-11-30T13:24:04Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Raimund Bauer offered this suggestion (paraphrased):\n\n\"Maybe we could do git-commit -a  _only_ if the index matches HEAD, and\notherwise keep current behavior?  So people who don't care about the\nindex won't get tripped up, and when you do have a dirty index, you get\ntold about it?\"\n\nJohannes Schindelin pointed out that this isn't the right thing to do for\nan --amend, so that is checked for.\n\nAdditionally, it's probably not the right thing to do if any files are\nspecified with \"--only\" or \"--include\", so they turn this behaviour off\nas well.\n\nI've also output a message as suggested by Andreas Ericsson.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n git-commit.sh |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 81c3a0c..fabfeae 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -265,6 +265,14 @@ $1\"\n done\n case \"$edit_flag\" in t) no_edit= ;; esac\n \n+# Clever commit - if this commit would do nothing, then make it an \"all\"\n+# commit\n+if [ -z \"$(git-diff-index --cached --name-only HEAD)\" \\\n+\t-a -z \"$amend\" -a -z \"$only\" -a -z \"$also\" ]; then\n+\techo \"Nothing to commit but changes in working tree. Assuming 'git commit -a'\"\n+\tall=t\n+fi\n+\n ################################################################\n # Sanity check options\n \n-- \n1.4.4.1.g3ece-dirty\n"},{"id":"295222","messageId":"fcaeb9bf0611300532x77c7fc8aq2ba77ff57b81cc05@mail.gmail.com","threadId":"43444","inReplyTo":"200611301324.04993.andyparkins@gmail.com","subject":"Re: [PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2006-11-30T13:32:23Z","receivedAt":"2006-11-30T13:32:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"> diff --git a/git-commit.sh b/git-commit.sh\n> index 81c3a0c..fabfeae 100755\n> --- a/git-commit.sh\n> +++ b/git-commit.sh\n> @@ -265,6 +265,14 @@ $1\"\n>  done\n>  case \"$edit_flag\" in t) no_edit= ;; esac\n>\n> +# Clever commit - if this commit would do nothing, then make it an \"all\"\n> +# commit\n> +if [ -z \"$(git-diff-index --cached --name-only HEAD)\" \\\n> +       -a -z \"$amend\" -a -z \"$only\" -a -z \"$also\" ]; then\n> +       echo \"Nothing to commit but changes in working tree. Assuming 'git commit -a'\"\n\nThis is hardly seen as the editor will immediately pop up. Better\npause a second or put it in commit template (I'd prefer the latter).\n\n> +       all=t\n> +fi\n> +\n>  ################################################################\n>  # Sanity check options\n>\n> --\n> 1.4.4.1.g3ece-dirty\n-- \n"},{"id":"297748","messageId":"ekmmvf$hsr$1@sea.gmane.org","threadId":"43444","inReplyTo":"fcaeb9bf0611300532x77c7fc8aq2ba77ff57b81cc05@mail.gmail.com","subject":"Re: [PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-30T13:41:51Z","receivedAt":"2006-11-30T13:41:51Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Nguyen Thai Ngoc Duy wrote:\n\n>> +# Clever commit - if this commit would do nothing, then make it an \"all\"\n>> +# commit\n>> +if [ -z \"$(git-diff-index --cached --name-only HEAD)\" \\\n>> +       -a -z \"$amend\" -a -z \"$only\" -a -z \"$also\" ]; then\n>> +       echo \"Nothing to commit but changes in working tree. Assuming 'git commit -a'\"\n> \n> This is hardly seen as the editor will immediately pop up. Better\n> pause a second or put it in commit template (I'd prefer the latter).\n\nWell, if it is VISUAL editor, you would see this. But adding this\nto template is certainly good idea.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"294811","messageId":"200611301501.43436.andyparkins@gmail.com","threadId":"43444","inReplyTo":"fcaeb9bf0611300532x77c7fc8aq2ba77ff57b81cc05@mail.gmail.com","subject":"[PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-11-30T15:01:43Z","receivedAt":"2006-11-30T15:01:43Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Raimund Bauer offered this suggestion (paraphrased):\n\n\"Maybe we could do git-commit -a  _only_ if the index matches HEAD, and\notherwise keep current behavior?  So people who don't care about the\nindex won't get tripped up, and when you do have a dirty index, you get\ntold about it?\"\n\nJohannes Schindelin pointed out that this isn't the right thing to do for\nan --amend, so that is checked for. Additionally, it's probably not the\nright thing to do if any files are specified with \"--only\" or\n\"--include\", so they turn this behaviour off as well.\n\nNguyen Thai Ngoc Duy asked that git-commit let you know it's done this\nby adding an extra comment to the commit message.\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n git-commit.sh |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 81c3a0c..b391257 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -265,6 +265,16 @@ $1\"\n done\n case \"$edit_flag\" in t) no_edit= ;; esac\n \n+# Clever commit - if this commit would do nothing, then make it an \"all\"\n+# commit\n+if [ -z \"$(git-diff-index --cached --name-only HEAD)\" \\\n+\t-a -z \"$amend\" -a -z \"$only\" -a -z \"$also\" ]; then\n+\techo \"# There was nothing to commit but changes were detected in the\" > $GIT_DIR/SQUASH_MSG\n+\techo \"# working tree. 'git commit -a' mode activated.\" >> $GIT_DIR/SQUASH_MSG\n+\techo \"#\" >> $GIT_DIR/SQUASH_MSG\n+\tall=t\n+fi\n+\n ################################################################\n # Sanity check options\n \n-- \n1.4.4.1.g3ece-dirty\n"},{"id":"294818","messageId":"ekmu7u$ddh$1@sea.gmane.org","threadId":"43444","inReplyTo":"200611301501.43436.andyparkins@gmail.com","subject":"Re: [PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Salikh Zakirov","fromEmail":"salikh.zakirov@intel.com","sentAt":"2006-11-30T15:43:53Z","receivedAt":"2006-11-30T15:43:53Z","isPatch":true,"sender":{"key":"salikh.zakirov@gmail.com","avatar":null},"body":"Andy Parkins wrote:\n> Raimund Bauer offered this suggestion (paraphrased):\n> \n> \"Maybe we could do git-commit -a  _only_ if the index matches HEAD, and\n> otherwise keep current behavior?  So people who don't care about the\n> index won't get tripped up, and when you do have a dirty index, you get\n> told about it?\"\n\nBrilliant solution!\n"},{"id":"298380","messageId":"ekn0ne$nuk$1@sea.gmane.org","threadId":"43444","inReplyTo":"200611301501.43436.andyparkins@gmail.com","subject":"Re: [PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-30T16:28:15Z","receivedAt":"2006-11-30T16:28:15Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Andy Parkins wrote:\n\n> Raimund Bauer offered this suggestion (paraphrased):\n> \n> \"Maybe we could do git-commit -a  _only_ if the index matches HEAD, and\n> otherwise keep current behavior?  So people who don't care about the\n> index won't get tripped up, and when you do have a dirty index, you get\n> told about it?\"\n> \n> Johannes Schindelin pointed out that this isn't the right thing to do for\n> an --amend, so that is checked for. Additionally, it's probably not the\n> right thing to do if any files are specified with \"--only\" or\n> \"--include\", so they turn this behaviour off as well.\n> \n> Nguyen Thai Ngoc Duy asked that git-commit let you know it's done this\n> by adding an extra comment to the commit message.\n\nInsount on #git pointed out fragility of this solution with respect\nto adding/removing/moving files, which dirties index (which might not be\nunderstood by newbie user: \"git commit\" used to work, but doesn't work the\nsame when I added some files).\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"296563","messageId":"200612011059.01659.andyparkins@gmail.com","threadId":"43444","inReplyTo":"ekn0ne$nuk$1@sea.gmane.org","subject":"Re: [PATCH] Make git-commit cleverer - have it figure out whether it needs -a automatically","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-12-01T10:59:00Z","receivedAt":"2006-12-01T10:59:00Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Thursday 2006 November 30 16:28, Jakub Narebski wrote:\n\n> Insount on #git pointed out fragility of this solution with respect\n> to adding/removing/moving files, which dirties index (which might not be\n> understood by newbie user: \"git commit\" used to work, but doesn't work the\n> same when I added some files).\n\nIt does, provided they only added files and didn't change anything else.  If \nthey did then we're out of it for this patch anyway.\n\nAnyway, this is only meant to help ease people into the index.  As discussed \nelsewhere, hiding the index is a silly policy.\n\nThis patch isn't /just/ for the newbies by the way (who are already confused, \nso that hasn't changed), I know about the index, but I still like it.  \nRemember, all it's really saying is \"when commit would do nothing, do \nsomething\".  So it only takes away an option that you can't have been using \nanyway because it didn't do anything.\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\n"}]}