mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-25 11:37:56 +00:00
tools: Add a git-svn bootstrap script
codified version of https://wiki.freebsd.org/GitWorkflow/GitSvn#Using_git-svn Approved by: emaste (mentor) Suggested by: Warner Losh (imp) Differential Revision: https://reviews.freebsd.org/D16528
This commit is contained in:
parent
0dbdecfd4f
commit
be223cad78
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=337157
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -3,3 +3,4 @@
|
||||
*.cpp diff=cpp
|
||||
*.hpp diff=cpp
|
||||
*.py diff=python
|
||||
. svn-properties=svn:executable=tools/tools/git/git-svn-init
|
||||
|
@ -157,3 +157,10 @@ and it will do its thing and leave the tree on the master branch.
|
||||
|
||||
Your tree must be clean to start this, and while it tries to catch
|
||||
some failures, not all of them have been allowed for.
|
||||
|
||||
IV. git-svn-init
|
||||
git-svn-init is a script that initializes the right git-svn connection as
|
||||
outlined in https://wiki.freebsd.org/GitWorkflow/GitSvn. It would be a precursor
|
||||
to the script git-svn-rebase. The script contains help, but generally you can
|
||||
run the script with no arguments and it will attempt to set up both src and
|
||||
ports repositories.
|
||||
|
195
tools/tools/git/git-svn-init
Executable file
195
tools/tools/git/git-svn-init
Executable file
@ -0,0 +1,195 @@
|
||||
#!/bin/sh
|
||||
|
||||
# $FreeBSD$
|
||||
|
||||
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
#
|
||||
# Copyright(c) 2018 Intel Corporation.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
|
||||
# This is the codified version of what was/is on the wiki page for using git in
|
||||
# your workflow. It sets up proper repositories, with the correct remotes.
|
||||
|
||||
# Environment variables which can be overridden if desired. Not worth
|
||||
# parameterizing them.
|
||||
GIT_IN_PATH=$(which git)
|
||||
GIT=${GIT-${GIT_IN_PATH}}
|
||||
|
||||
GIT_PORTS_REPO=${GIT_PORTS_REPO-git://github.com/freebsd/freebsd-ports.git}
|
||||
GIT_SVN_PORTS_ROOT_URI=${GIT_SVN_PORTS_ROOT_URI-svn.freebsd.org/ports}
|
||||
GIT_SVN_PORTS_URI=${GIT_SVN_PORTS_URI-repo.freebsd.org/ports}
|
||||
|
||||
GIT_SRC_REPO=${GIT_SRC_REPO-git://github.com/freebsd/freebsd.git}
|
||||
GIT_SVN_SRC_ROOT_URI=${GIT_SVN_SRC_ROOT_URI-svn.freebsd.org/base}
|
||||
GIT_SVN_SRC_URI=${GIT_SVN_SRC_URI-repo.freebsd.org/base}
|
||||
|
||||
GIT_SVN_PORTS_PUSH_URI=$GIT_SVN_PORTS_URI
|
||||
GIT_SVN_SRC_PUSH_URI=$GIT_SVN_SRC_URI
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: git-svn-init: [-b base_path] [-n] [-p] [-s]
|
||||
|
||||
git-svn-init will instantiate git repositories for src, and ports and connect
|
||||
them to the upstream SVN repository. By default it will attempt to do this for
|
||||
both ports and src under freebsd in the current working directory.
|
||||
-b Base path for the clone operation (default: freebsd)
|
||||
-n Dry run
|
||||
-p Exclude ports
|
||||
-s Exclude src
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
clone()
|
||||
{
|
||||
echo "Cloning ${3}"
|
||||
${GIT} clone "$repo" -o upstream "$base"/${3}
|
||||
}
|
||||
|
||||
svn_init()
|
||||
{
|
||||
# init git-svn to point to the subversion repo:
|
||||
${GIT} svn init -Thead --rewrite-root=svn+ssh://$1 svn+ssh://$2 .
|
||||
|
||||
# Replace to use upstream instead of the default origin
|
||||
# TODO: Do this from git svn init
|
||||
${GIT} config svn-remote.svn.fetch head:refs/remotes/upstream/trunk
|
||||
|
||||
# Committers need to use proper URL for dcommit
|
||||
${GIT} config svn-remote.svn.pushurl svn+ssh://$3
|
||||
|
||||
}
|
||||
|
||||
svn_check()
|
||||
{
|
||||
cat <<EOF
|
||||
[svn-remote "svn"]
|
||||
url = svn+ssh://repo.freebsd.org/base
|
||||
rewriteRoot = svn+ssh://svn.freebsd.org/base
|
||||
pushurl = svn+ssh://repo.freebsd.org/base
|
||||
fetch = head:refs/remotes/upstream/trunk
|
||||
EOF
|
||||
[ -z ${DRY_RUN} ] && grep -A4 'svn-remote "svn"' .git/config
|
||||
}
|
||||
|
||||
svn_connect()
|
||||
{
|
||||
# Now make a git branch 'trunk' for git-svn to follow. What we want to
|
||||
# do it set it to point to the final commit in upstream/svn_head.
|
||||
local svn_head_sha=$(git show-ref upstream/svn_head|cut -d" " -f1)
|
||||
${GIT} update-ref refs/remotes/upstream/trunk $svn_head_sha # git-svn really needs this branch
|
||||
}
|
||||
|
||||
svn_fetch()
|
||||
{
|
||||
${GIT} svn fetch
|
||||
}
|
||||
|
||||
git_pulls()
|
||||
{
|
||||
# Get pull requests from the repos:
|
||||
${GIT} config --add remote.upstream.fetch '+refs/pull/*:refs/remotes/upstream/pull/*'
|
||||
${GIT} fetch
|
||||
}
|
||||
|
||||
git_checkout()
|
||||
{
|
||||
# Arrange to have 'master' reference 'trunk'
|
||||
${GIT} checkout trunk
|
||||
|
||||
# Delete master
|
||||
${GIT} branch -D master
|
||||
|
||||
# Make master really be trunk
|
||||
${GIT} checkout -b master trunk
|
||||
}
|
||||
|
||||
rebase()
|
||||
{
|
||||
${GIT} svn rebase
|
||||
}
|
||||
|
||||
doit()
|
||||
{
|
||||
local repo=${1}
|
||||
local base=${2}
|
||||
|
||||
if [ "$3" = "src" ] ; then
|
||||
local svn_root_uri=$GIT_SVN_SRC_ROOT_URI
|
||||
local svn_uri=$GIT_SVN_SRC_URI
|
||||
local svn_push_uri=$GIT_SVN_SRC_PUSH_URI
|
||||
else
|
||||
local svn_root_uri=$GIT_SVN_PORTS_ROOT_URI
|
||||
local svn_uri=$GIT_SVN_PORTS_URI
|
||||
local svn_push_uri=$GIT_SVN_PORTS_PUSH_URI
|
||||
fi
|
||||
|
||||
clone ${repo} ${base} ${3}
|
||||
|
||||
cd "$base"/${3}
|
||||
svn_init $svn_root_uri $svn_uri $svn_push_uri
|
||||
svn_check $(basename $svn_uri) # get base or ports, not src/ports.
|
||||
svn_connect
|
||||
svn_fetch
|
||||
git_pulls
|
||||
git_checkout
|
||||
rebase
|
||||
|
||||
cd -
|
||||
}
|
||||
|
||||
ports=1
|
||||
source=1
|
||||
while getopts "hb:nr:sp" opt; do
|
||||
case "$opt" in
|
||||
b)
|
||||
base_path="$OPTARG"
|
||||
;;
|
||||
n)
|
||||
DRY_RUN=1
|
||||
;;
|
||||
p)
|
||||
ports=0
|
||||
;;
|
||||
s)
|
||||
source=0
|
||||
;;
|
||||
h|*)
|
||||
usage
|
||||
exit 0
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -z "${DRY_RUN}" ] ; then
|
||||
GIT='echo git'
|
||||
fi
|
||||
|
||||
if [ "$source" -eq 1 ]; then
|
||||
doit ${GIT_SRC_REPO} ${base_path:-freebsd} "src"
|
||||
fi
|
||||
|
||||
if [ "$ports" -eq 1 ]; then
|
||||
doit ${GIT_PORTS_REPO} ${base_path:-freebsd} "ports"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user