Merge pull request #168 from legalsylvain/master
[odoo/odoo.git] / checkout.sh
1 #/bin/sh
2 set -e
3
4 ODOO=https://github.com/odoo/odoo.git
5 DEV=https://github.com/odoo-dev/odoo.git
6
7 usage () {
8 cat <<EOF
9 Usage: $0 [-m] [COPYNAME]
10
11 Checks out and sets up the Odoo git repository for "internal" development.
12
13 * Checks out the "production" repository (production branches) as the "odoo"
14   remote
15 * Checks out the "development" repository (for employee development branches)
16   as the "dev" repository
17
18 By default, the working copy is "odoo"
19
20 Options:
21 -h        displays this help text
22 -m        includes github's merge refs. These are the pull requests to "odoo"
23           which merge cleanly into the main repository, after having applied
24           them to said repository
25 EOF
26 }
27
28 while getopts :hm opt
29 do
30     case $opt in
31         h)
32             usage
33             exit 0
34             ;;
35         m)
36             include_merge=yes
37             ;;
38         *)
39             usage
40             exit 1
41             ;;
42     esac
43 done
44
45 shift $((OPTIND-1))
46 copyname=${1:-"odoo"}
47
48 # Collect basic configuration data, ensures correct configuration of that repo
49 printf "Enter your full name: "
50 read name
51 printf "Enter your (work) email: "
52 read email
53
54 # create & set up repo
55 git init $copyname
56 cd $copyname
57
58 git config user.name "$name"
59 git config user.email "$email"
60
61 # pre-push script preventing push to odoo repo by default. Git just execs
62 # them, so they need a correct shebang and exec bit
63 # if things get more extensive, should probably use git init templates
64 cat <<EOF > .git/hooks/pre-push
65 #!/bin/sh
66 remote="\$1"
67 url="\$2"
68
69 if [ "\$url" != "$ODOO" ]
70 then
71     exit 0
72 fi
73
74 echo "Pushing to the odoo remote ($ODOO) is forbidden, push to the dev remote"
75 echo
76 echo "See git help push if you really want to push to odoo"
77 exit 1
78
79 EOF
80 chmod +x .git/hooks/pre-push
81
82 # add basic repos as remotes
83 git remote add odoo $ODOO
84 git remote add dev $DEV
85
86 if [ $include_merge ]
87 then
88     git remote add merge $ODOO
89     git config remote.merge.fetch '+refs/pull/*/merge:refs/remotes/merge/*'
90 fi
91
92 echo
93 git remote update
94
95 exit 0