* Getting git to help my memory
@ 2011-07-05 21:34 Evan Driscoll
2011-07-05 22:08 ` Paul Ebermann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Evan Driscoll @ 2011-07-05 21:34 UTC (permalink / raw)
To: git
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".)
Is there a way I can get git to print a "don't forget to push!" reminder
after it commits?
The best way I can think of is to put a post-commit hook in there. I haven't
tried it but I'd assume it would work, but would have to be on a
per-repository basis instead of global.
(I use git mostly for just my own projects, and almost always mostly in sort
of a centralized setup: I've got one bare *the* repository that I clone, and
push to and pull from that rather than between the copies. For a variety of
reasons, I'm pretty sure that model wouldn't work super well for me.)
Thanks,
Evan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Getting git to help my memory
2011-07-05 21:34 Getting git to help my memory Evan Driscoll
@ 2011-07-05 22:08 ` Paul Ebermann
2011-07-05 23:52 ` Ben Walton
2011-07-06 7:52 ` Matthieu Moy
2 siblings, 0 replies; 4+ messages in thread
From: Paul Ebermann @ 2011-07-05 22:08 UTC (permalink / raw)
To: git; +Cc: Evan Driscoll
Evan Driscoll schrieb:
> 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".)
>
> Is there a way I can get git to print a "don't forget to push!" reminder
> after it commits?
>
> The best way I can think of is to put a post-commit hook in there. I haven't
> tried it but I'd assume it would work, but would have to be on a
> per-repository basis instead of global.
Yes, I just tried this. Here is the output (from adding a file in the test branch):
---
$ git commit
Don't forget to push!
[test ceabc34] adding test.txt.
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 test.txt
---
The output is a bit hidden here. Maybe coloring would help here a bit.
Is it really intentional that post-commit is called
*before* the informational output here?
I have no idea on how to automatically add the hooks to all
the repositories - AFAIK git clone will not copy these.
Paŭlo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Getting git to help my memory
2011-07-05 21:34 Getting git to help my memory Evan Driscoll
2011-07-05 22:08 ` Paul Ebermann
@ 2011-07-05 23:52 ` Ben Walton
2011-07-06 7:52 ` Matthieu Moy
2 siblings, 0 replies; 4+ messages in thread
From: Ben Walton @ 2011-07-05 23:52 UTC (permalink / raw)
To: Evan Driscoll; +Cc: git
Excerpts from Evan Driscoll's message of Tue Jul 05 17:34:18 -0400 2011:
Hi Evan,
> The best way I can think of is to put a post-commit hook in there. I
> haven't tried it but I'd assume it would work, but would have to be
> on a per-repository basis instead of global.
I use this script as a post-commit hook in a few places...
--snip--
#!/bin/bash
echo -e "\e[32;01m"
echo "Don't forget to \`git push\` this..."
echo -e "\e[0m"
--snip--
HTH.
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Getting git to help my memory
2011-07-05 21:34 Getting git to help my memory Evan Driscoll
2011-07-05 22:08 ` Paul Ebermann
2011-07-05 23:52 ` Ben Walton
@ 2011-07-06 7:52 ` Matthieu Moy
2 siblings, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2011-07-06 7:52 UTC (permalink / raw)
To: Evan Driscoll; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: git-gc-fsck.sh --]
[-- Type: text/x-sh, Size: 1361 bytes --]
#! /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"
[-- Attachment #3: git-foreach --]
[-- Type: application/octet-stream, Size: 3267 bytes --]
#! /bin/bash
usage () {
cat << EOF
Usage:
$(basename $0) [options] update Update the cached list of repositories.
$(basename $0) [options] add Add a directory to the cached list of repositories.
$(basename $0) [options] ls|list Show the cached list of repositories.
$(basename $0) [options] do cmd args Execute "cmd args" in each repository.
Options:
--help, -h This help message.
--dir, -d Directory where repositories should be searched for
--verbose, -v Be verbose
--quiet Don't display commands before executing them
Files:
~/.git-foreach List of repositories.
Updated by git foreach update, used by git foreach do.
~/.git-foreach-dirs
List of directories where Git repositories should be looked for
~/.git-foreach-exclude
List of paths to exclude in 'git foreach update' (regexp).
EOF
}
dirs=("$HOME")
if [ -f ~/.git-foreach-dirs ]; then
dirs=()
while read line; do
# expand ~ & friends.
eval line=$line
dirs=("${dirs[@]}" $line)
done < ~/.git-foreach-dirs
fi
git_update () {
rm -f "$HOME"/.git-foreach.old
mv "$HOME"/.git-foreach "$HOME"/.git-foreach.old
find "${dirs[@]}" \! \( -name sshfs -o -name tmp \) -wholename \*/refs/heads | \
sed 's@\(/.git\|\)\(/logs\|\)/refs/heads$@@' | \
uniq | grep -v -f "$HOME/.git-foreach-exclude" | \
tee "$HOME/.git-foreach" >&2
diff -U 0 "$HOME"/.git-foreach.old "$HOME"/.git-foreach
}
git_ls () {
cat "$HOME/.git-foreach"
}
git_add () {
cd "$1" || exit 1
if ! git rev-parse HEAD > /dev/null 2>&1; then
echo "$1: not a git repository"
fi
pwd >> "$HOME/.git-foreach"
}
git_do () {
(
> /tmp/git-foreach-error.$$
IFS="
"
cat "$HOME/.git-foreach" | while read file; do
(
cd "$file" 2>> /tmp/git-foreach-error.$$ || exit 1 # exit just from subshell.
IFS=" "
if [ "$quiet" = "no" ]; then
echo "Running $@ in directory $file ..."
fi
"$@" || echo "$file (exit $?)" >> /tmp/git-foreach-error.$$
)
done 3>&1
)
if [ "$(cat /tmp/git-foreach-error.$$)" != "" ]; then
echo "Errors occured:"
cat /tmp/git-foreach-error.$$
rm -f /tmp/git-foreach-error.$$
exit 1
fi
rm -f /tmp/git-foreach-error.$$
}
verbose=no
quiet=no
while test $# -ne 0; do
case "$1" in
"--help"|"-h")
usage
exit 0
;;
"--verbose"|"-v")
verbose=yes
;;
"--quiet"|"-q")
quiet=yes
;;
"--dir"|"-d")
shift
dirs="$(cd -P "$1"; pwd)"
;;
"update")
shift
git_update "$@"
exit 0
;;
"do")
shift
git_do "$@"
exit 0
;;
"list"|"ls")
shift
git_ls "$@"
exit 0
;;
"add")
shift
git_add "$@"
exit 0
;;
*)
echo "unrecognized option $1"
usage
exit 1
;;
esac
shift
done
if [ "$verbose" = yes ]; then
echo "Directories to look into:"
echo "${dirs[@]}"
fi
usage
[-- Attachment #4: Type: text/plain, Size: 273 bytes --]
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/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-06 7:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05 21:34 Getting git to help my memory Evan Driscoll
2011-07-05 22:08 ` Paul Ebermann
2011-07-05 23:52 ` Ben Walton
2011-07-06 7:52 ` Matthieu Moy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.