Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (79 sloc) 2.052 kB
89725fd @jgm Initial commit.
authored
1 #!/bin/sh
2 #
3 # This hook does two things:
4 #
5 # 1. update the "info" files that allow the list of references to be
6 # queries over dumb transports such as http
7 #
8 # 2. if this repository looks like it is a non-bare repository, and
9 # the checked-out branch is pushed to, then update the working copy.
10 # This makes "push" function somewhat similarly to darcs and bzr.
11 #
12 # To enable this hook, make this file executable by "chmod +x post-update".
13
14 git-update-server-info
15
16 is_bare=$(git-config --get --bool core.bare)
17
18 if [ -z "$is_bare" ]
19 then
20 # for compatibility's sake, guess
21 git_dir_full=$(cd $GIT_DIR; pwd)
22 case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
23 fi
24
25 update_wc() {
26 ref=$1
27 echo "Push to checked out branch $ref" >&2
28 if [ ! -f $GIT_DIR/logs/HEAD ]
29 then
30 echo "E:push to non-bare repository requires a HEAD reflog" >&2
31 exit 1
32 fi
33 if (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)
34 then
35 wc_dirty=0
36 else
37 echo "W:unstaged changes found in working copy" >&2
38 wc_dirty=1
39 desc="working copy"
40 fi
41 if git diff-index --cached HEAD@{1} >/dev/null
42 then
43 index_dirty=0
44 else
45 echo "W:uncommitted, staged changes found" >&2
46 index_dirty=1
47 if [ -n "$desc" ]
48 then
49 desc="$desc and index"
50 else
51 desc="index"
52 fi
53 fi
54 if [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]
55 then
56 new=$(git rev-parse HEAD)
57 echo "W:stashing dirty $desc - see git-stash(1)" >&2
58 ( trap 'echo trapped $$; git symbolic-ref HEAD "'"$ref"'"' 2 3 13 15 ERR EXIT
59 git-update-ref --no-deref HEAD HEAD@{1}
60 cd $GIT_WORK_TREE
61 git stash save "dirty $desc before update to $new";
62 git-symbolic-ref HEAD "$ref"
63 )
64 fi
65
66 # eye candy - show the WC updates :)
67 echo "Updating working copy" >&2
68 (cd $GIT_WORK_TREE
69 git-diff-index -R --name-status HEAD >&2
70 git-reset --hard HEAD)
71 }
72
73 if [ "$is_bare" = "false" ]
74 then
75 active_branch=`git-symbolic-ref HEAD`
76 export GIT_DIR=$(cd $GIT_DIR; pwd)
77 GIT_WORK_TREE=${GIT_WORK_TREE-..}
78 for ref
79 do
80 if [ "$ref" = "$active_branch" ]
81 then
82 update_wc $ref
83 fi
84 done
85 fi
Something went wrong with that request. Please try again.