Bash macro that does not let me "git push" after 3am

3

Alright, so basically I've managed to cause problems by pushing very late at night. How could I change git push (without forcefully changing git write-protected files) to need "Are you sure?" dialog between 3am and 6am.

Joonatan Samuel

Posted 2017-09-20T09:40:42.553

Reputation: 145

have you looked at git hooks (especially pre-push hook) ? – vera – 2017-09-20T12:09:18.483

Hey! I was I not aware of hooks before :) You beat me to the answer, thanks :) – Joonatan Samuel – 2017-09-20T12:29:59.473

I didn't see your comment, already provided a sample of pre-push hook. – vera – 2017-09-20T12:31:03.630

Answers

3

You can install git pre-push hook. Create the file $MYREPO/.git/hooks/pre-push:

#!/bin/bash
hour=$(date +%H)
if [ $hour -ge 3 ] && [ $hour -lt 6 ]; then
    read reply "Are you sure ? [yes/anything else]"
    if [ "$reply" == "yes" ]; then
        return 0;
    else
        echo "Cancelling ..."
        return 1
    fi
else
    return 0
fi

vera

Posted 2017-09-20T09:40:42.553

Reputation: 760