{"thread":{"id":"23873","subject":"can pre-commit hook accept user input?","startedAt":"2010-05-22T01:41:11Z","lastAt":"2010-05-22T12:11:15Z","messageCount":3,"participants":["Neal Kreitzinger","Shawn O. Pearce","Marc Weber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"142077","messageId":"ht7co7$d0s$1@dough.gmane.org","threadId":"23873","inReplyTo":null,"subject":"can pre-commit hook accept user input?","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-05-22T01:41:11Z","receivedAt":"2010-05-22T01:41:11Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"Hi,\n\nCan the pre-commit hook accept user input?  I'm new to linux and bash \nscripting and here's what I'm trying.  (It appears to work in a manually \nexecuted script.)  The 'read' commands do not let me input anything when \nrunning in a hook. (I've inserted a non-loop test at the beginning to be \nsure.)  The script just keeps going with a value of 'nothing' in the input \nvariable.  This, of course, causes and endless loop in the code that I \nreally want to use.\n\n#!/bin/bash\n#*******************************************************************************\n#* PGM NAME: pre-commit  A hook script to verify what is about to be \ncommitted**\n#*                       Called by git-commit with no arguments.  The hook \n**\n#*                       should exit with non-zero status after issuing an \n**\n#*                       appropriate message if it wants to stop the commit. \n**\n#*                          MODIFICATION LOG \n**\n#* PROJ#   DATE PRGMR        DESCRIPTION \n**\n#* 000057 04/10 NEAL K    INSPECT SOURCE FILES FOR HEADER USER/DATE STAMP. \n**\n#*                        PROMPT FOR VERIFICATION OF DD CHANGES. WARNING: \n**\n#*                        TRACKED WORKING COPY FILES WILL BE STAGED IF THEIR \n**\n#*                        INDEX ENTRY DIFFERS FROM THE HEAD COMMIT! \n**\n#* 000378 05/10 NEAL K    BUGFIX: ONLY INSPECT/STAGE OBJECTS WHOSE INDEX \nENTRY**\n#*                        DIFFERS FROM THE HEAD COMMIT. MOD: MORE INFO IN \n**\n#*                        HEADER STAMP WARNING. WARN/PROMPT TO STAGE WORKING \n**\n#*                        COPIES OF STAGED FILES. \n**\n#*******************************************************************************\necho \"Start pre-commit hook... Confirmation:\"\necho enter your name\nread NAME\necho \"hi $NAME\"\n# \nx\nCONFIRMED=\"N\"\nuntil [ $CONFIRMED = \"Y\" ]; do\n  echo \"Any unstaged changes to staged files will be staged. \nContinue?(Y/N/H)elp\"\n  read CONFIRM\n  case \"$CONFIRM\" in\n    \"Y\" )\n      echo \"Re-staging algorithm approved by User. Continue pre-commit \nhook...\"\n      CONFIRMED=\"Y\";;\n    \"N\" )\n      echo \"Commit Aborted by User.\"\n      exit 3;;\n    \"H\" )\n      echo \"Example:\"\n      echo \"1. After the last commit, you changed RCUSTMNT and staged it. \nWe'll call this  \"\n      echo \"   staged version of RCUSTMNT 'RCUSTMNT NEW'.\"\n      echo \"2. Then you modified RCUSTMNT again, but did not stage it again. \nWe'll call    \"\n      echo \"   this working copy version of RCUSTMNT 'RCUSTMNT NEWEST'. \"\n      echo \"THIS SCRIPT WILL STAGE AND COMMIT 'RCUSTMNT NEWEST'!\"\n      echo \"*This behavior is based on the notion that you will not have \nunstaged changes  \"\n      echo \" to your staged source files.\";;\n    * )\n      echo \"Please enter Y, N, or H (Help)\";;\n  esac\ndone\nABORTMSG=\"Commit Aborted!\"\nDIFFFILES=`git diff-index HEAD --cached --name-only SRC/*/*`\nif [ $? -ne 0 ]; then\n  echo \"Error running git diff-index command\"\n  echo $ABORTMSG\n  exit 4\nfi\nfor FILES in ${DIFFFILES}\n  do\n# \nx\n# \n12345678901234567890\n  echo \"inspecting working copy & staged copy of staged source file:$FILES\"\n  if [ ! -r ${FILES} ]; then\n    echo \"${FILES} needs read permission\"\n    echo $ABORTMSG\n    exit 6\n  fi\n  if [ ! -w ${FILES} ]; then\n    echo \"${FILES} needs write permission\"\n    echo $ABORTMSG\n    exit 6\n  fi\n  CHKUSER=$(/usr/bin/head -1 ${FILES} | /bin/egrep -c '\\$User\\$|\\$User:')\n  CHKDATE=$(/usr/bin/head -1 ${FILES} | /bin/egrep -c '\\$Date\\$|\\$Date:')\n  if [ ${CHKUSER} -ne 1 -o ${CHKDATE} -ne 1 ]; then\n# \n80\n    echo \"User/Date Stamp Header Comment, e.g. ':\\$User$ \\$Date$' missing in \nfirst line of\"\n    echo \"source file:${FILES}\"\n    echo $ABORTMSG\n    exit 7\n  fi\n  sed -i \"s/\\\\\\$User[^\\\\\\$]*\\\\\\$/\\\\\\$User\\\\\\$/; \ns/\\\\\\$Date[^\\\\\\$]*\\\\\\$/\\\\\\$Date\\\\\\$/; s/\\\\\\$User[^\\\\\\$]*\\\\\\$/\\\\\\$User: \n`whoami`\\\\\\$/; s/\\\\\\$Date[^\\\\\\$]*\\\\\\$/\\\\\\$Date: `date`\\\\\\$/\" ${FILES}\n  if [ $? -ne 0 ]; then\n    echo \"Error in user/date stamp substitution for file ${FILES}\"\n    echo $ABORTMSG\n    exit 5\n  fi\n  git add ${FILES}\n  if [ $? -ne 0 ]; then\n    echo \"Error in re-staging (git add) of user/date stamped file ${FILES}\"\n    echo $ABORTMSG\n    exit 8\n  fi\n  done\n# We are not checking error codes on purpose for DDGIT\necho \"Running Data Dictionary report (DDGIT)...\"\nZ -b -o/dev/null DDGIT\nwait\necho \"Checking for any changes in Data Dictionary report (DDGIT)...\"\nDIFFDDGIT=`git diff --exit-code DDGIT`\nif [ $? -ne 0 ]; then\n  echo \"Warning: Data Dictionary report (DDGIT) indicates changes to Data \nDictionary!\"\n  echo \"If DD.idx and DD.dat have changed then a change in DDGIT is \nexpected.\"\n  echo \"Otherwise, a change in DDGIT is not expected.\"\n  echo \"REVIEW THE OLD&NEW DDGIT OUTPUT DIFF AND VERIFY THAT *ALL* CHANGES \nARE EXPECTED!\"\n  echo \"If the format of the DDGIT output is suspect, then consult with the \nDD Admin.\"\n  echo \"After validating *ALL* DD changes, run 'git add DDGIT' and rerun the \ncommit.\"\n  echo $ABORTMSG\n  exit 9\nfi\necho \"Info: no changes found in Data Dictionary report (DDGIT).\"\necho \"...end of pre-commit hook.\"\nexit 0\n\n\nv/r,\nNeal \n"},{"id":"142078","messageId":"20100522014524.GF16470@spearce.org","threadId":"23873","inReplyTo":"ht7co7$d0s$1@dough.gmane.org","subject":"Re: can pre-commit hook accept user input?","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-05-22T01:45:24Z","receivedAt":"2010-05-22T01:45:24Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Neal Kreitzinger <neal@rsss.com> wrote:\n> Can the pre-commit hook accept user input?\n\nNo.  None of the hooks accept user input.\n\n-- \nShawn.\n"},{"id":"142095","messageId":"1274530138-sup-6441@nixos","threadId":"23873","inReplyTo":"ht7co7$d0s$1@dough.gmane.org","subject":"Re: can pre-commit hook accept user input?","fromName":"Marc Weber","fromEmail":"marco-oweber@gmx.de","sentAt":"2010-05-22T12:11:15Z","receivedAt":"2010-05-22T12:11:15Z","isPatch":false,"sender":{"key":"marco-oweber@gmx.de","avatar":null},"body":"Excerpts from Neal Kreitzinger's message of Sat May 22 03:41:11 +0200 2010:\n> Can the pre-commit hook accept user input?  I'm new to linux and bash \n\nMaybe try describing why you want to add this hook?\nWhich purpose does it have?\nMaybe there is another way to get what you want.\n\nThere may be some ways using new ttys and such to be able to read from\nstdin again. Maybe even use tools such as xmessage or gui inputs.\n\nBut this should be a personal hack only then - because I don't know\nexactly those hooks are run. So tell more about the \"why\" and maybe\nyou'll get much feedback about the \"how\" to do it.\n\nMarc Weber\n"}]}