Skip to content
This repository
Newer
Older
100755 73 lines (64 sloc) 2.152 kb
22b433a3 » Frédéric Perrin
2011-08-29 Don't assume that bash is in /bin
1 #!/usr/bin/env bash
2
3 set -e
fccc6851 » MLstate
2011-06-21 Initial open-source release
4
5 help () (
6 echo "$0:"
7 echo " - Initialise some sane standard git config"
8 echo " - Possibly setup for linking with extra repositories"
9 echo "Options:"
10 echo " --extra-repo <name> add the given repo inside ./repos/"
11 echo " --link [dir] link to existing repositories in [dir] (by default, ../)"
12 echo " instead of cloning a fresh repo"
13 echo " --help display this help message"
14 echo
15 )
16
17 # This is used for e.g. ./init.sh --extra-repo git://github.com/MLstate/tictactopa.git
18 # Do not remove this, we actually use it
19 get_repo_name() { x=${1##*:}; x=${x##*/}; x=${x%.git}; echo $x; }
20
21 REPOS=()
22 LINK=""
23 LINKDIR=".."
24
25 while [ $# -gt 0 ]; do
26 case $1 in
27 --help|-h)
28 help; exit 0;;
29 --extra-repo)
30 if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
31 shift
32 REPOS[${#REPOS[@]}]=$1
33 ;;
34 --link)
35 if [ $# -ge 2 ] && [ "${2#-}" = "$2" ]; then shift; LINKDIR=$1; fi
36 LINK=1
37 ;;
38 *) echo "Error: unknown option $1"
39 esac
40 shift
41 done
42
43 git config branch.master.rebase true
44 git config --global branch.autosetuprebase always
45
46 echo "OK: git setup complete"
47
48 mkdir -p repos
49
50 # don't forget to add those to .gitignore to avoid conflicts
51 for repo_link in "${REPOS[@]}"; do
52 r=$(get_repo_name $repo_link)
53 if [ -e "repos/$r" ]; then
54 echo "repo $r is already there, skipping"
55 elif [ -n "$LINK" ]; then
56 if [ ! -d "$LINKDIR/$r/.git" ]; then
57 echo "Error: could not find a valid git repo at $LINKDIR/$r"
58 else
59 RELLINK=$LINKDIR
60 if [ "${RELLINK#/}" = "$RELLINK" ]; then RELLINK="../$RELLINK"; fi
61 ln -s "$RELLINK/$r" repos/
62 echo "OK: repo $r linked in repos/"
63 fi
64 else
65 cd repos
66 # we assume the full link is given, like github repository,
67 # e.g. git://github.com/MLstate/tictactopa.git used by passtracker
68 CLONE_PATH="$repo_link"
69 git clone $CLONE_PATH
70 cd ..
71 echo "OK: repo $r cloned in repos/"
72 fi
73 done
Something went wrong with that request. Please try again.