mirror of
https://github.com/redmine/redmine.git
synced 2025-11-02 03:15:57 +01:00
Merged nbc branch @ r1812 (commit access permission and reposman improvements).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1814 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -6,52 +6,49 @@
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# reposman [ -h | --help ] [ -v | --verbose ] [ -V | --version ] [ -q | --quiet ] -s /var/svn -r redmine.host.org
|
||||
# example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo
|
||||
# reposman -s /var/svn -r redmine.mydomain.foo
|
||||
# reposman [OPTIONS...] -s [DIR] -r [HOST]
|
||||
#
|
||||
# Examples:
|
||||
# reposman --svn-dir=/var/svn --redmine-host=redmine.example.net
|
||||
# reposman -s /var/svn -r redmine.example.net -u http://svn.example.net
|
||||
#
|
||||
# == Arguments (mandatory)
|
||||
#
|
||||
# -s, --svn-dir=DIR
|
||||
# use DIR as base directory for svn repositories
|
||||
#
|
||||
# -r, --redmine-host=HOST
|
||||
# assume Redmine is hosted on HOST.
|
||||
# you can use :
|
||||
# * -r redmine.mydomain.foo (will add http://)
|
||||
# * -r http://redmine.mydomain.foo
|
||||
# * -r https://mydomain.foo/redmine
|
||||
# -s, --svn-dir=DIR use DIR as base directory for svn repositories
|
||||
# -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples:
|
||||
# -r redmine.example.net
|
||||
# -r http://redmine.example.net
|
||||
# -r https://example.net/redmine
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# -o, --owner=OWNER
|
||||
# owner of the repository. using the rails login allow user to browse
|
||||
# the repository in Redmine even for private project
|
||||
#
|
||||
# -u, --url=URL
|
||||
# the base url Redmine will use to access your repositories. This
|
||||
# will be used to register the repository in Redmine so that user
|
||||
# doesn't need to do anything. reposman will add the identifier to this url :
|
||||
#
|
||||
# -u https://my.svn.server/my/reposity/root # if the repository can be access by http
|
||||
# -u file:///var/svn/ # if the repository is local
|
||||
# if this option isn't set, reposman won't register the repository
|
||||
#
|
||||
# -t, --test
|
||||
# only show what should be done
|
||||
#
|
||||
# -h, --help:
|
||||
# show help and exit
|
||||
#
|
||||
# -v, --verbose
|
||||
# verbose
|
||||
#
|
||||
# -V, --version
|
||||
# print version and exit
|
||||
#
|
||||
# -q, --quiet
|
||||
# no log
|
||||
#
|
||||
# -o, --owner=OWNER owner of the repository. using the rails login
|
||||
# allow user to browse the repository within
|
||||
# Redmine even for private project
|
||||
# -u, --url=URL the base url Redmine will use to access your
|
||||
# repositories. This option is used to automatically
|
||||
# register the repositories in Redmine. The project
|
||||
# identifier will be appended to this url. Examples:
|
||||
# -u https://example.net/svn
|
||||
# -u file:///var/svn/
|
||||
# if this option isn't set, reposman won't register
|
||||
# the repositories in Redmine
|
||||
# -c, --command=COMMAND use this command instead of "svnadmin create" to
|
||||
# create a repository. This option can be used to
|
||||
# create non-subversion repositories
|
||||
# --scm SCM vendor used to register the repository in
|
||||
# Redmine (default: Subversion). Can be one of the
|
||||
# other supported SCM: Bazaar, Darcs, Filesystem,
|
||||
# Git, Mercurial (case sensitive).
|
||||
# This option should be used when both options --url
|
||||
# and --command are used.
|
||||
# -f, --force force repository creation even if the project
|
||||
# repository is already declared in Redmine
|
||||
# -t, --test only show what should be done
|
||||
# -h, --help show help and exit
|
||||
# -v, --verbose verbose
|
||||
# -V, --version print version and exit
|
||||
# -q, --quiet no log
|
||||
|
||||
require 'getoptlong'
|
||||
require 'rdoc/usage'
|
||||
@@ -59,14 +56,18 @@ require 'soap/wsdlDriver'
|
||||
require 'find'
|
||||
require 'etc'
|
||||
|
||||
Version = "1.0"
|
||||
Version = "1.1"
|
||||
SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--scm', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--test', '-t', GetoptLong::NO_ARGUMENT],
|
||||
['--force', '-f', GetoptLong::NO_ARGUMENT],
|
||||
['--verbose', '-v', GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-V', GetoptLong::NO_ARGUMENT],
|
||||
['--help' , '-h', GetoptLong::NO_ARGUMENT],
|
||||
@@ -81,6 +82,9 @@ $svn_owner = 'root'
|
||||
$use_groupid = true
|
||||
$svn_url = false
|
||||
$test = false
|
||||
$command = "svnadmin create"
|
||||
$force = false
|
||||
$scm = 'Subversion'
|
||||
|
||||
def log(text,level=0, exit=false)
|
||||
return if $quiet or level > $verbose
|
||||
@@ -95,8 +99,11 @@ begin
|
||||
when '--redmine-host'; $redmine_host = arg.dup
|
||||
when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
|
||||
when '--url'; $svn_url = arg.dup
|
||||
when '--scm'; $scm = arg.dup; log("Invalid SCM: #{$scm}", 0, true) unless SUPPORTED_SCM.include?($scm)
|
||||
when '--command'; $command = arg.dup
|
||||
when '--verbose'; $verbose += 1
|
||||
when '--test'; $test = true
|
||||
when '--force'; $force = true
|
||||
when '--version'; puts Version; exit
|
||||
when '--help'; RDoc::usage
|
||||
when '--quiet'; $quiet = true
|
||||
@@ -110,6 +117,12 @@ if $test
|
||||
log("running in test mode")
|
||||
end
|
||||
|
||||
# Make sure command is overridden if SCM vendor is not Subversion
|
||||
if $scm != 'Subversion' && $command == 'svnadmin create'
|
||||
log("Please use --command option to specify how to create a #{$scm} repository.", 0, true)
|
||||
end
|
||||
|
||||
|
||||
$svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
|
||||
|
||||
if ($redmine_host.empty? or $repos_base.empty?)
|
||||
@@ -133,7 +146,7 @@ rescue => e
|
||||
log("Unable to connect to #{wsdl_url} : #{e}", 0, true)
|
||||
end
|
||||
|
||||
projects = soap.Projects
|
||||
projects = soap.ProjectsWithRepositoryEnabled
|
||||
|
||||
if projects.nil?
|
||||
log('no project found, perhaps you forgot to "Enable WS for repository management"', 0, true)
|
||||
@@ -201,6 +214,13 @@ projects.each do |project|
|
||||
log("\tmode change on #{repos_path}");
|
||||
|
||||
else
|
||||
# if repository is already declared in redmine, we don't create
|
||||
# unless user use -f with reposman
|
||||
if $force == false and not project.repository.nil?
|
||||
log("\trepository for project #{project.identifier} already exists in Redmine", 1)
|
||||
next
|
||||
end
|
||||
|
||||
project.is_public ? File.umask(0002) : File.umask(0007)
|
||||
|
||||
if $test
|
||||
@@ -211,7 +231,8 @@ projects.each do |project|
|
||||
|
||||
begin
|
||||
set_owner_and_rights(project, repos_path) do
|
||||
raise "svnadmin create #{repos_path} failed" unless system("svnadmin", "create", repos_path)
|
||||
command = "#{$command} #{repos_path}"
|
||||
raise "#{command} failed" unless system( command )
|
||||
end
|
||||
rescue => e
|
||||
log("\tunable to create #{repos_path} : #{e}\n")
|
||||
@@ -219,7 +240,7 @@ projects.each do |project|
|
||||
end
|
||||
|
||||
if $svn_url
|
||||
ret = soap.RepositoryCreated project.identifier, "#{$svn_url}#{project.identifier}"
|
||||
ret = soap.RepositoryCreated project.identifier, $scm, "#{$svn_url}#{project.identifier}"
|
||||
if ret > 0
|
||||
log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user