git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Getting git to help my memory

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jul 6, 2011, 07:52 UTC
Message-ID
<vpqpqlnkfqv.fsf@bauges.imag.fr>
In-Reply-To
<loom.20110705T232905-603@post.gmane.org>
Evan Driscoll <driscoll@cs.wisc.edu> 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@imag.fr 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"

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/
Previous: Ben Walton
Message 4 of 4 in “Getting git to help my memory”
  1. Evan DriscollJul 5, 2011
  2. Paul EbermannJul 5, 2011
  3. Ben WaltonJul 5, 2011
  4. Matthieu MoyJul 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.