Re: Getting git to help my memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Evan Driscoll <driscoll@xxxxxxxxxxx> writes:

> I have a somewhat unusual question. I often forget to push after committing,
> and a few times this has come back to bite me. (One time I didn't even really
> realize for a couple months because I was working on other stuff, so
> unraveling the conflicts was "fun".)

I have a cron job that sends me a mail with the list of "unpushed"
repositaries on my account every nights (it also runs "git fsck", "git
gc", and writes some .keep files to prevent "git gc" from repacking
large packs and be friendly with backups and unison).

It's not really cleaned up, and may well work just for me, but in case
you're interested, the scripts are attached:

* git-gc-fsck.sh is the script itself

* git-foreach is a home-made git command to manage a set of unrelated
  repositories. Essentially, one can

  git foreach update   => run some "find" commands in your $HOME to find
                          repositories.

  git foreach do blah  => run command blah in each repository.

#! /bin/sh

status=0
subject=""
email=Matthieu.Moy@xxxxxxx
body=/tmp/git-gc-fsck.$$

diff=$(git-foreach update)

if [ "$diff" != "" ]; then
    (
	echo "Git repository list changed:"
	echo "$diff"
	echo
    ) >> "$body"
    subject="$subject change"
fi

unpushed=$(git foreach --quiet do sh -c 'u=$(git rev-parse @{upstream} 2>/dev/null);
if [ $? = 0 ]; then
    graph=$(git log --graph --oneline $u..);
    if [ "$graph" != "" ]; then
        pwd
        echo "$graph" | sed "s/^/    /"
        echo
    fi
    graph=""
fi')

if [ "$unpushed" != "" ]; then
    (
	echo "Some Git repositories have unpushed content:"
	echo "$unpushed"
	echo
    ) >> "$body"
    subject="$subject unpushed"
fi

failed_fsck=$(git-foreach do git fsck 2>&1)
fsck_status=$?

echo "$failed_fsck"

if [ "$fsck_status" != 0 ]; then
    subject="FSCK $subject"
    status=1
    (
	echo "Some Git repositories FAILED to fsck:"
	echo "$failed_fsck"
	echo
    ) >> "$body"
elif git-foreach do git keep-pack --size +10M && \
    git-foreach do git gc > /dev/null; then
    echo "git gc succeeded"
else
    echo "git gc failed, fsck succeeded. This is VERY strange ..."
    subject="GC $subject"
    status=1
fi

if [ "$subject" != "" ]; then
    mail -s "Git cron: $subject" "$email" < "$body"
    echo "Email sent to $email : $subject"
    cat "$body"
    rm -f "$body"
fi

exit "$status"

Attachment: git-foreach
Description: Binary data

BTW, if you really always want to push after commit, you can as well
have a post-commit-hook that does the push for you. But you lose part of
the power of Git by doing so (you can't rebase -i before pushing for
example).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]