##// END OF EJS Templates
* reposman can create git repository with "--scm git" option...
Nicolas Chuche -
r1864:a07a6d4aa4ba
parent child
Show More
@@ -2,15 +2,15
2 2
3 3 # == Synopsis
4 4 #
5 # reposman: manages your svn repositories with Redmine
5 # reposman: manages your repositories with Redmine
6 6 #
7 7 # == Usage
8 8 #
9 9 # reposman [OPTIONS...] -s [DIR] -r [HOST]
10 10 #
11 11 # Examples:
12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net
13 # reposman -s /var/svn -r redmine.example.net -u http://svn.example.net
12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
13 # reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git
14 14 #
15 15 # == Arguments (mandatory)
16 16 #
@@ -24,7 +24,12
24 24 #
25 25 # -o, --owner=OWNER owner of the repository. using the rails login
26 26 # allow user to browse the repository within
27 # Redmine even for private project
27 # Redmine even for private project. If you want to share repositories
28 # through Redmine.pm, you need to use the apache owner.
29 # --scm=SCM the kind of SCM repository you want to create (and register) in
30 # Redmine (default: Subversion). reposman is able to create Git
31 # and Subversion repositories. For all other kind (Bazaar,
32 # Darcs, Filesystem, Mercurial) you must specify a --command option
28 33 # -u, --url=URL the base url Redmine will use to access your
29 34 # repositories. This option is used to automatically
30 35 # register the repositories in Redmine. The project
@@ -35,13 +40,8
35 40 # the repositories in Redmine
36 41 # -c, --command=COMMAND use this command instead of "svnadmin create" to
37 42 # create a repository. This option can be used to
38 # create non-subversion repositories
39 # --scm SCM vendor used to register the repository in
40 # Redmine (default: Subversion). Can be one of the
41 # other supported SCM: Bazaar, Darcs, Filesystem,
42 # Git, Mercurial (case sensitive).
43 # This option should be used when both options --url
44 # and --command are used.
43 # create repositories other than subversion and git kind.
44 # This command override the default creation for git and subversion.
45 45 # -f, --force force repository creation even if the project
46 46 # repository is already declared in Redmine
47 47 # -t, --test only show what should be done
@@ -49,6 +49,11
49 49 # -v, --verbose verbose
50 50 # -V, --version print version and exit
51 51 # -q, --quiet no log
52 #
53 # == References
54 #
55 # You can find more information on the redmine's wiki : http://www.redmine.org/wiki/redmine/HowTos
56
52 57
53 58 require 'getoptlong'
54 59 require 'rdoc/usage'
@@ -82,7 +87,6 $svn_owner = 'root'
82 87 $use_groupid = true
83 88 $svn_url = false
84 89 $test = false
85 $command = "svnadmin create"
86 90 $force = false
87 91 $scm = 'Subversion'
88 92
@@ -91,6 +95,30 def log(text,level=0, exit=false)
91 95 exit 1 if exit
92 96 end
93 97
98 def system_or_raise(command)
99 raise "\"#{command}\" failed" unless system command
100 end
101
102 module SCM
103
104 module Subversion
105 def self.create(path)
106 system_or_raise "svnadmin create #{path}"
107 end
108 end
109
110 module Git
111 def self.create(path)
112 Dir.mkdir path
113 Dir.chdir(path) do
114 system_or_raise "git --bare init --shared"
115 system_or_raise "git-update-server-info"
116 end
117 end
118 end
119
120 end
121
94 122 begin
95 123 opts.each do |opt, arg|
96 124 case opt
@@ -98,7 +126,7 begin
98 126 when '--redmine-host'; $redmine_host = arg.dup
99 127 when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
100 128 when '--url'; $svn_url = arg.dup
101 when '--scm'; $scm = arg.dup; log("Invalid SCM: #{$scm}", 0, true) unless SUPPORTED_SCM.include?($scm)
129 when '--scm'; $scm = arg.dup.capitalize; log("Invalid SCM: #{$scm}", 0, true) unless SUPPORTED_SCM.include?($scm)
102 130 when '--command'; $command = arg.dup
103 131 when '--verbose'; $verbose += 1
104 132 when '--test'; $test = true
@@ -116,12 +144,15 if $test
116 144 log("running in test mode")
117 145 end
118 146
119 # Make sure command is overridden if SCM vendor is not Subversion
120 if $scm != 'Subversion' && $command == 'svnadmin create'
121 log("Please use --command option to specify how to create a #{$scm} repository.", 0, true)
147 # Make sure command is overridden if SCM vendor is not handled internally (for the moment Subversion and Git)
148 if $command.nil?
149 begin
150 scm_module = SCM.const_get($scm)
151 rescue
152 log("Please use --command option to specify how to create a #{$scm} repository.", 0, true)
153 end
122 154 end
123 155
124
125 156 $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
126 157
127 158 if ($redmine_host.empty? or $repos_base.empty?)
@@ -230,8 +261,11 projects.each do |project|
230 261
231 262 begin
232 263 set_owner_and_rights(project, repos_path) do
233 command = "#{$command} #{repos_path}"
234 raise "#{command} failed" unless system( command )
264 if scm_module.nil?
265 system_or_raise "#{$command} #{repos_path}"
266 else
267 scm_module.create(repos_path)
268 end
235 269 end
236 270 rescue => e
237 271 log("\tunable to create #{repos_path} : #{e}\n")
General Comments 0
You need to be logged in to leave comments. Login now