-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush-updates.sh
executable file
·95 lines (81 loc) · 2.01 KB
/
push-updates.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
COMMITMSG="Site update"
EXEC_DIR=$(readlink -f "$(dirname "$0" )" );
CURR_DIR=$(readlink -f "$(pwd)" );
#enter the exec dir (where the repo lies)
cd "$EXEC_DIR"
#detect DVCS
#try git
git status > /dev/null 2> /dev/null
ISGIT=$?
if [ $ISGIT -eq 0 ] ; then
#bingo, it is git
DVCSTYPE="git"
NRMODCOMMAND="git status --porcelain"
DCVSADD="git add -A ."
DCVSREMOVE1="git ls-files --deleted"
DCVSREMOVE2="cat" #dummy for indirection
DCVSCOMMIT="git commit"
fi
#try mercurial
hg status > /dev/null 2> /dev/null
ISMERCURIAL=$?
if [ $ISMERCURIAL -eq 0 ] ; then
#must be mercurial
DVCSTYPE="mercurial"
NRMODCOMMAND="hg stat"
DCVSADD="hg add"
DCVSREMOVE1="hg addremove" #I need two commands for Git
DCVSREMOVE2="cat" #dummy for indirection
DCVSCOMMIT="hg comm"
fi
#permit setting the commit message by parameter
if [ $# -ge 1 ] ; then
COMMITMSG="$1"
fi
#starting sync
echo "-> Starting auto sync..."
NRMOD=$( $NRMODCOMMAND | wc -l )
if [ $NRMOD -gt 0 ] ; then
echo "--> Adding new files, removing old, commiting undeposited changes..."
#we have modified files not deposited; do them
#there is a bug of out-of-memory when there are too many files
$DCVSADD #add new files
$DCVSREMOVE1 | $DCVSREMOVE2 #calculate renames
$DCVSCOMMIT -m "$COMMITMSG"
fi
if [ $DVCSTYPE = "git" ] ; then
#pull is short for fetch and merge
git pull ;
#put back the modifications
git push ;
else
#are there incoming?
hg incoming > /dev/null
INCOMING=$?
#are there outgoing?
hg outgoing > /dev/null
OUTGOING=$?
if [ $INCOMING -eq 0 ] ; then
#we have distant changesets; pull
hg pull
if [ $OUTGOING -gt 0 ] ; then
#no local changes, just update local repo
hg up ;
fi
fi
if [ $OUTGOING -eq 0 ] ; then
#we have local changes
#if distant also, merge and deposit back
if [ $INCOMING -eq 0 ] ; then
hg merge
hg commit -m "Commit after merge"
fi
hg push
fi
fi
echo -e "--> Done\n\n\n"
#read -n 1 -p "Press any key to continue..."
bash ./send-to-server.sh
#go back to the current dir
cd "$CURR_DIR"