blob: d8d6aaa1d09db9fcbb19470d7d618bae1760ca43 (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/bin/bash
#
# Commit both on git and svn
#
# Parameters
ARGS="$*"
# Check if a file is inside a git repository
# Usage: git_folder <file>
function git_folder {
local folder="$1" folder folders dir_list cwd
if [ -d "$folder/.git" ]; then
GIT_FOLDER="$folder"
return
fi
# reverse folder order
dir_list="`echo $folder | tr '/' ' '`"
for i in $dir_list; do
folders="$i $folders"
done
cwd="`pwd`"
cd $folder
for i in $folders; do
cd ..
if [ -d "$(pwd)/.git" ]; then
GIT_FOLDER="$(pwd)"
cd $cwd
return
fi
done
cd $cwd
return 1
}
# Check if a folder is inside a git repository
function is_git {
# simple git folder checker
# usage: is_git <folder>
if [ -z "$1" ]; then
return 1
elif [ ! -d "$1" ]; then
return 1
elif [ -d "$1/.git" ]; then
return
else
( cd "$1" && git status &> /dev/null )
if [ "$?" != "128" ]; then
return
else
return 1
fi
fi
}
# Check if a folder is inside a svn repository
function is_svn {
# simple svn folder checker
# usage: is_svn <folder>
if [ -d "$1/.svn" ]; then
return
else
return 1
fi
}
# Push to repositories
function git_push {
if [ "`git remote | wc -l`" == "0" ]; then
return
elif git remote | grep -q 'all'; then
git push all --all
elif git remote | grep -q 'origin'; then
git push --all
fi
}
# Check user information
function git_user {
if ! grep -q "^\[user\]" $GIT_FOLDER/.git/config; then
if echo $ARGS | grep -q -- '--config'; then
grep -A 2 "^\[user\]" $HOME/.gitconfig >> $GIT_FOLDER/.git/config
else
echo "No user configuration section found in the repository."
echo "This might be a privacy issue"
echo ""
if [ -e "$HOME/.gitconfig" ]; then
echo "You should try to use your default setting:"
echo ""
if [ "$GIT_FOLDER" == "$(pwd)" ]; then
echo "cat <<EOF >> .git/config"
else
echo "cat <<EOF >> $GIT_FOLDER/.git/config"
fi
grep -A 2 "^\[user\]" $HOME/.gitconfig
echo "EOF"
echo ""
echo "Use --config if you want these lines to be added at .git/config"
fi
exit 1
fi
fi
}
# Main
if [ ! -z "$1" ]; then
if is_svn .; then
svn commit -m "$*"
fi
if is_git .; then
git_folder $(pwd)
git_user
git commit -a -m "$*"
git_push
fi
fi
|