开发者

git default remote branch with gitolite

I'm using gitflow branching model for some projects. For this reason when someone clone a repository I'd like that the default checked out branch would be the develop branch rather than master.

For public projects hosted on Github I can control this using the Admin section for that repository, but for private repository managed with gitolite the only working solution I found is to ssh int开发者_运维知识库o the hosting machine and use the git update-ref command directly in the bare repository.

Is there any way to do this remotely, i.e. without the need to ssh into remote machine?


After a couple of hours spent in implementing VonC suggestion I sadly found out that a set-head script already exists in gitolite repository :-(

However I've already implemented my version for that so I'm posting it here. I implemented an additional feature which can restrict the set-head command only to repository creators. Maybe I will fork the gitolite project and add that feature to the original version.

BTW here is my version:

#!/bin/sh

. $(dirname $0)/adc.common-functions

[ $# -eq 2 ] || die "usage: $0 <repo> <branch>"

if [ $SDB_WRITER_ALLOWED ]; then
  # this will check only for write permission on the given repository
  get_rights_and_owner $1 # this also set $repo variable
  [ -z "$perm_write" ] && die "You don't have write permission on $repo"
else
  # require a repository creator to change default branch
  valid_owned_repo $1
fi

# move to repo dir
cd "$GL_REPO_BASE_ABS/$repo.git"

# check for branch existence
match=`git branch | sed 's/^\( \|*\) //' | grep $2`
# this will check for an exact match in branch name  
[ "$2" = "$match" ] || die "Unable to find branch $2 in repository $repo"

# update the default checked out branch
git symbolic-ref HEAD refs/heads/$match   

echo "Head branch for repository $1 updated to $2"

Here it's the pull request if someone is interested


The problem with an ssh access for that kind of command is that you need an interactive shell access, which is considered as "bad" (because you can then type any command you want).

The official gitolite solution, which still involves ssh though, is to define an admin defined command:

It's rather important to me (and presumably others in the "corporate" world) to separate permission to push to the "gitolite-admin" repo from unrestricted shell access to the server. This issue has been visited often in the past.

Until now, though, this was binary -- you either had full shell access or none at all.
If there were tasks that legitimately needed to be done from the shell on the server, it often meant you had to break that separation or load the few people who did have shell access already.

Now, however, it is possible to provide scripts to do what you want, and put them in $GL_ADC_PATH. contrib/adc

Those scripts have access to the following variables:

  • GL_USER -- the name of the user invoking the command
  • GL_BINDIR -- the directory containing all the binaries (in particular, gitolite.pm, which is all we really care about here)
  • GL_REPO_BASE_ABS -- the absolute path of the base directory containing all the repos

You have all the informations you need to go to the right repo.git and perform the git update-index there.


Now (in gitolite v3) I cannot see the set-head script and use a gitolite trigger doing this command: git symbolic-ref HEAD refs/heads/develop. You can name the trigger file whatever you like and start it from .gitolite.rc in the POST_GIT section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜