{"thread":{"id":"25939","subject":"How to \"pre-populate\" a git message","startedAt":"2010-12-03T17:51:52Z","lastAt":"2010-12-03T19:36:40Z","messageCount":3,"participants":["Patrick Doyle","Jonathan Nieder","Dirk Süsserott"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"157227","messageId":"AANLkTim=dVxVLL31aEBrjw7OhXpdYOjAO9Sk16gGP3zJ@mail.gmail.com","threadId":"25939","inReplyTo":null,"subject":"How to \"pre-populate\" a git message","fromName":"Patrick Doyle","fromEmail":"wpdster@gmail.com","sentAt":"2010-12-03T17:51:52Z","receivedAt":"2010-12-03T17:51:52Z","isPatch":false,"sender":{"key":"wpdster@gmail.com","avatar":null},"body":"Once in a while, I would like to run some scripts that will\nautomatically generate some files that I keep maintained in my\nrepository.  (Yes, I know that I shouldn't have to keep them version\ncontrolled if I can regenerate them, but it's easier to check out old\nversions of the files than it is to check out old versions of the\nrepository, wait 1/2 hour to regenerate the files, and then look at\nthem).\n\nI also like to review the files before they get committed.\n\nIs there any way I can \"pre-populate\" the commit message so that I can\nrun my \"regenerate\" command, review the differences, and then commit\nthe changes with my prewritten message?\n\n--wpd\n"},{"id":"157244","messageId":"20101203192950.GA14561@burratino","threadId":"25939","inReplyTo":"AANLkTim=dVxVLL31aEBrjw7OhXpdYOjAO9Sk16gGP3zJ@mail.gmail.com","subject":"Re: How to \"pre-populate\" a git message","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-12-03T19:29:50Z","receivedAt":"2010-12-03T19:29:50Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"(+cc: Jeff and Thomas, pioneers in application of notes)\n\nHi!\n\nPatrick Doyle wrote:\n\n> Once in a while, I would like to run some scripts that will\n> automatically generate some files that I keep maintained in my\n> repository.  (Yes, I know that I shouldn't have to keep them version\n> controlled if I can regenerate them, but it's easier to check out old\n> versions of the files than it is to check out old versions of the\n> repository, wait 1/2 hour to regenerate the files, and then look at\n> them).\n\nNot what you asked, but here's an alternative approach.\n\nThe idea is that sometimes you might not want to wait 1/2 hour\nfor each commit and that keeping generated files in this case is\nmore about caching than tracking content.\n\nSo, wouldn't it be nice if you could ask to remember these\ngenerated files _after_ commiting?  It works like this:\n\nAn expensive command to generate some files can be run\n(asynchronously?) by explicit request, commit hook, or cron job.\nFirst it would check if the file is already available.\n\n\tif git notes --ref=generated/expensive.result show HEAD >/dev/null 2>&1\n\tthen\n\t\t# already cached\n\t\texit 0\n\telif test $? != 1\n\tthen\n\t\t# exit with error message\n\t\texec git notes --ref=generated/expensive.result show HEAD\n\tfi\n\t# no note found; let's make one!\n\t... expensive operation ...\n\tblob=$(git hash-object -w expensive.result) &&\n\tgit notes --ref=generated/expensive.result add -C \"$blob\" HEAD ||\n\t\texit\n\nThe result could be retrieved on checkout (see the post-checkout hook)\nor explicitly.\n\n\tgit notes --ref=generated/expensive.result show HEAD >expensive.result+\n\tmv expensive.result+ expensive.result\n\nSee v1.7.2-rc0~159^2~1 (diff: cache textconv output, 2010-04-01) for\na similar (but not identical) example.  Unfortunately the notes-cache\nfacility used there is not currently exposed for scripted use.\n\nSorry for the digression.  To return to your question:\n\n> I also like to review the files before they get committed.\n\nMaybe \"git commit -v\" or the prepare-commit-msg hook could help?\n\nThanks for an example.\nJonathan\n"},{"id":"157248","messageId":"4CF946C8.6050009@dirk.my1.cc","threadId":"25939","inReplyTo":"AANLkTim=dVxVLL31aEBrjw7OhXpdYOjAO9Sk16gGP3zJ@mail.gmail.com","subject":"Re: How to \"pre-populate\" a git message","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2010-12-03T19:36:40Z","receivedAt":"2010-12-03T19:36:40Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Am 03.12.2010 18:51 schrieb Patrick Doyle:\n> Once in a while, I would like to run some scripts that will\n> automatically generate some files that I keep maintained in my\n> repository.\n>\n> I also like to review the files before they get committed.\n>\n> Is there any way I can \"pre-populate\" the commit message so that I can\n> run my \"regenerate\" command, review the differences, and then commit\n> the changes with my prewritten message?\n>\n> --wpd\n\nYou can either commit the changes with the \"-m <msg>\" or with the\n\"-F <file>\" switch. In your case I'd suggest the latter:\n\n1. regenerate your files and include a step that generates\n    a commit message and stores that in a file, say \"commit.msg\".\n2. review the changes\n3. add all your files (except for \"commit.msg\", of course)\n4. commit:\n      $ git commit -F commit.msg\n\nThe other way would be the -m switch, but then you'd have to supply\nthe message by yourself somehow:\n$ git commit -m \"These files were generated at ...\"\n\n\nHTH,\n     Dirk\n"}]}