Created
June 26, 2018 20:53
-
-
Save aeisenberg/b9e0b1ca47db44b306fd058e377c46ae to your computer and use it in GitHub Desktop.
Clones a repository from gerrit and includes a default /refs/for/* clause
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh -e | |
server=gerrit.example.com # change to your own server | |
username=$1 | |
project=$2 | |
url=ssh://${username}@${server}:29418/${project} | |
git clone ${url} | |
cd ${project} | |
git config gerrit.createchangeid true | |
git config remote.origin.url ${url} | |
git config remote.origin.push HEAD:refs/for/master | |
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* | |
scp -p -P 29418 ${username}@${server}:hooks/commit-msg .git/hooks/ |
Based on this Stackoverflow question.
Minor: you don't need lines 9 and 11, git clone
configures those two that way for you.
Somewhat more serious: you might want to make sure there are two arguments and if not, print a usage message. Still not too big a problem since if the arguments are inappropriate, the git clone
step will fail and the -e
flag will make the script exit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place this file on your path and you can call it using:
This will automatically add the default remote origin with a push to
refs/for/master
.