-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpost-receive.sh
40 lines (34 loc) · 1.35 KB
/
post-receive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
cd ..
export GIT_DIR=.git
git reset --hard
refs=`cat - | head -1 | cut -d' ' -f1,2`
ref_begin=`echo $refs | cut -d' ' -f1`
ref_end=`echo $refs | cut -d' ' -f2`
if [ "$ref_begin" = "0000000000000000000000000000000000000000" ]; then
range="" # first push, empty repos.
else
range="$ref_begin..$ref_end"
fi
articles_dir=`git config --get fugitive.articles-dir`
added_files=`git log $range --name-status --pretty="format:" | \
grep -E '^A' | cut -f2 | sort | uniq`
modified_files=`git log $range --name-status --pretty="format:" | \
grep -E '^M' | cut -f2 | sort | uniq`
deleted_files=`git log $range --name-status --pretty="format:" | \
grep -E '^D' | cut -f2 | sort | uniq`
tmpart=`mktemp fugitiveXXXXXX`
tmpadd=`mktemp fugitiveXXXXXX`
tmpmod=`mktemp fugitiveXXXXXX`
tmpdel=`mktemp fugitiveXXXXXX`
ls "$articles_dir"/* > "$tmpart"
echo "$added_files" | tr " " "\n" > "$tmpadd"
echo "$modified_files" | tr " " "\n" > "$tmpmod"
echo "$deleted_files" | tr " " "\n" > "$tmpdel"
deleted_files=`comm -23 --nocheck-order "$tmpdel" "$tmpart"`
echo "$deleted_files" | tr " " "\n" > "$tmpdel"
deleted_files=`comm -23 --nocheck-order "$tmpdel" "$tmpadd"`
added_files=`comm -12 --nocheck-order "$tmpadd" "$tmpart"`
echo "$added_files" | tr " " "\n" > "$tmpadd"
modified_files=`comm -23 --nocheck-order "$tmpmod" "$tmpadd"`
rm "$tmpart" "$tmpadd" "$tmpmod" "$tmpdel"