0

I have written script to ZIP last commit on post-commit hook:

#!/bin/sh

echo "[post-commit] Commit done!"

exec < /dev/tty

while true; do
    read -p "[post-commit] Archive this commit? (Y/n) " yn
    if [ "$yn" = "" ]; then
        yn='Y'
    fi
    case $yn in
        [Yy] ) exec git archive -o $(git log -1 --pretty=%B).zip $(git rev-parse HEAD) $(git diff --name-only $(git rev-parse HEAD)^..$(git rev-parse HEAD)); break;;
        [Nn] ) exit;;
        * ) echo "Please answer Yy or Nn for yes or no.";;
    esac
done

It's creating a ZIP file but .. empty, it's not storing changed files...
Anyone see where is bad?

Melebius
  • 6,183
  • 4
  • 39
  • 52
Vertisan
  • 720
  • 3
  • 14
  • 34

1 Answers1

1

As I see the -o $(git log -1 --pretty=%B).zip should specify a name of the archive. The %B prints you a commit message body text which could have spaces, new lines and a lot of other weird characters which could not go into a file name and break command line options.

Not sure what you are trying to achieve, so I do not know what to suggest to improve it. Probably you could use %f (i.e. sanitized subject line, suitable for a filename) instead of %B.

My best suggestion - just do not do such weird things ;)

kan
  • 28,279
  • 7
  • 71
  • 101
  • 1
    @David Also, you are over-using `rev-parse`. Most of the git commands work just fine with `HEAD`. – kan Dec 11 '17 at 10:57