Skip to content

Instantly share code, notes, and snippets.

@nikhgupta
Created January 25, 2011 13:09
Show Gist options
  • Save nikhgupta/794884 to your computer and use it in GitHub Desktop.
Save nikhgupta/794884 to your computer and use it in GitHub Desktop.
a bash script which automates creation of a local git repository, modifies gitolite.conf file as needed, and then syncs the repo with an online gitolite (and github) server you must have repos defined the way in attached gitolite.conf file
# gitolite conf
# please see conf/example.conf for details on syntax and features
# do not remove hashes from the following macros
# if you add a macro, remember to update ~/bin/init-gitolite.sh
@public-readable = #
@public-writable = testing #
@client-works = #
repo @client-works
RW+ = nikhgupta
repo @public-writable
RW+ = @all
repo @public-readable
R = @all
repo @all
RW+ = nikhgupta
#!/bin/bash -x
GITOLITE_ADMIN_DIR=/home/Stoic/www/git/gitolite-admin
GITSERVER=gitolite
GITHUB_USER=nikhgupta
TRACK_FILE=.init-gitolite
# check back which repo macro is the one, the user wants to add the repository in
case "$1" in
'-pr')
REPO_MACRO=public-readable
;;
'-pw')
REPO_MACRO=public-writable
;;
'-cw')
REPO_MACRO=client-works
;;
*)
REPO_MACRO=public-readable
;;
esac
# check if the INIT-GITOLITE has already been called for the current directory
if [ -f .git/$TRACK_FILE ]; then
echo init-gitolite has already been called for this repository.. exiting..
exit
fi
# if no repo name is provided, get a default based on directory name
if [ "x$2" == x"" ]; then
REPO_NAME=${PWD##*/}
else
REPO_NAME=$2
fi
GITOLITE_CONF=$GITOLITE_ADMIN_DIR/conf/gitolite.conf
# backup our existing Gitolite Configuration file
cp $GITOLITE_CONF $GITOLITE_CONF.bak
# make changes to our Gitolite Configuration file, if needed.
sed -e 's/\(@'"$REPO_MACRO"'.*\) #/\1 '"$REPO_NAME"' #/g' -i $GITOLITE_CONF
CURRENT_DIR=`pwd`
git init
echo ----------------------------------------------------------
echo Preparing for Commit
echo ----------------------------------------------------------
touch $TRACK_FILE
echo ----------------------------------------------------------
echo Created $TRACK_FILE file for preventing re-run of this script
echo ----------------------------------------------------------
git add .
git commit -am "First Sync with Gitolite Server"
echo ----------------------------------------------------------
echo Initializing bare repo on Gitolite Server
echo ----------------------------------------------------------
cd $GITOLITE_ADMIN_DIR
git add .
git commit -am "Added repo: $REPO_NAME"
git push
cd $CURRENT_DIR
git remote add $GITSERVER $GITSERVER:$REPO_NAME.git
echo ----------------------------------------------------------
echo Added Remote branch with name: $GITSERVER
echo ----------------------------------------------------------
echo Pushing Initial Commit to Gitolite Server
echo ----------------------------------------------------------
git push $GITSERVER --all
if [ "$3" == "github" ]; then
[email protected]:$GITHUB_USER/$REPO_NAME.git
git remote add github $GITHUB_REPO
echo ----------------------------------------------------------
echo Added Remote branch with name: github
echo ----------------------------------------------------------
echo Pushing Initial Commit to Github
echo ----------------------------------------------------------
git push github master
fi
echo
echo
echo --------------------------------------------
echo SUCCESSFULLY INITIALIZED LOCAL REPO AND SYNCED WITH GITOLITE REPO!!
echo --------------------------------------------
echo git clone $GITSERVER:$REPO_NAME
if [ "$3" == "github" ]; then
echo git clone $GITHUB_REPO
fi
echo --------------------------------------------
@nikhgupta
Copy link
Author

description

a bash script which automates creation of a local git repository, modifies gitolite.conf file as needed, and then syncs the repo with an online gitolite (and github) server
you must have repos defined the way in attached gitolite.conf file


usage:

runs the script with no github support, repo name is auto-detected via directory name the script is under, and repo is added to default macro (line: 20 for init-gitolite.sh)

./init-gitolite.sh

runs the script with no github support, repo name is auto-detected via directory name the script is run under

./init-gitolite.sh -pw

runs the script with no github support, repo name is provided at command-prompt

./init-gitolite.sh -pr repo_name

runs the script with github support, a repo_name must be provided, which matches github repo name

./init-gitolite.sh -cw repo_name github


notes

a remote repo with name: gitolite is added to the local repo.
if github is referenced, a remote repo with name: github is also added to the local repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment