##// 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 # == Synopsis
3 # == Synopsis
4 #
4 #
5 # reposman: manages your svn repositories with Redmine
5 # reposman: manages your repositories with Redmine
6 #
6 #
7 # == Usage
7 # == Usage
8 #
8 #
9 # reposman [OPTIONS...] -s [DIR] -r [HOST]
9 # reposman [OPTIONS...] -s [DIR] -r [HOST]
10 #
10 #
11 # Examples:
11 # Examples:
12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net
12 # reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
13 # reposman -s /var/svn -r redmine.example.net -u http://svn.example.net
13 # reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git
14 #
14 #
15 # == Arguments (mandatory)
15 # == Arguments (mandatory)
16 #
16 #
@@ -24,7 +24,12
24 #
24 #
25 # -o, --owner=OWNER owner of the repository. using the rails login
25 # -o, --owner=OWNER owner of the repository. using the rails login
26 # allow user to browse the repository within
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 # -u, --url=URL the base url Redmine will use to access your
33 # -u, --url=URL the base url Redmine will use to access your
29 # repositories. This option is used to automatically
34 # repositories. This option is used to automatically
30 # register the repositories in Redmine. The project
35 # register the repositories in Redmine. The project
@@ -35,13 +40,8
35 # the repositories in Redmine
40 # the repositories in Redmine
36 # -c, --command=COMMAND use this command instead of "svnadmin create" to
41 # -c, --command=COMMAND use this command instead of "svnadmin create" to
37 # create a repository. This option can be used to
42 # create a repository. This option can be used to
38 # create non-subversion repositories
43 # create repositories other than subversion and git kind.
39 # --scm SCM vendor used to register the repository in
44 # This command override the default creation for git and subversion.
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.
45 # -f, --force force repository creation even if the project
45 # -f, --force force repository creation even if the project
46 # repository is already declared in Redmine
46 # repository is already declared in Redmine
47 # -t, --test only show what should be done
47 # -t, --test only show what should be done
@@ -49,6 +49,11
49 # -v, --verbose verbose
49 # -v, --verbose verbose
50 # -V, --version print version and exit
50 # -V, --version print version and exit
51 # -q, --quiet no log
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 require 'getoptlong'
58 require 'getoptlong'
54 require 'rdoc/usage'
59 require 'rdoc/usage'
@@ -82,7 +87,6 $svn_owner = 'root'
82 $use_groupid = true
87 $use_groupid = true
83 $svn_url = false
88 $svn_url = false
84 $test = false
89 $test = false
85 $command = "svnadmin create"
86 $force = false
90 $force = false
87 $scm = 'Subversion'
91 $scm = 'Subversion'
88
92
@@ -91,6 +95,30 def log(text,level=0, exit=false)
91 exit 1 if exit
95 exit 1 if exit
92 end
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 begin
122 begin
95 opts.each do |opt, arg|
123 opts.each do |opt, arg|
96 case opt
124 case opt
@@ -98,7 +126,7 begin
98 when '--redmine-host'; $redmine_host = arg.dup
126 when '--redmine-host'; $redmine_host = arg.dup
99 when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
127 when '--owner'; $svn_owner = arg.dup; $use_groupid = false;
100 when '--url'; $svn_url = arg.dup
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 when '--command'; $command = arg.dup
130 when '--command'; $command = arg.dup
103 when '--verbose'; $verbose += 1
131 when '--verbose'; $verbose += 1
104 when '--test'; $test = true
132 when '--test'; $test = true
@@ -116,12 +144,15 if $test
116 log("running in test mode")
144 log("running in test mode")
117 end
145 end
118
146
119 # Make sure command is overridden if SCM vendor is not Subversion
147 # Make sure command is overridden if SCM vendor is not handled internally (for the moment Subversion and Git)
120 if $scm != 'Subversion' && $command == 'svnadmin create'
148 if $command.nil?
121 log("Please use --command option to specify how to create a #{$scm} repository.", 0, true)
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 end
154 end
123
155
124
125 $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
156 $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/)
126
157
127 if ($redmine_host.empty? or $repos_base.empty?)
158 if ($redmine_host.empty? or $repos_base.empty?)
@@ -230,8 +261,11 projects.each do |project|
230
261
231 begin
262 begin
232 set_owner_and_rights(project, repos_path) do
263 set_owner_and_rights(project, repos_path) do
233 command = "#{$command} #{repos_path}"
264 if scm_module.nil?
234 raise "#{command} failed" unless system( command )
265 system_or_raise "#{$command} #{repos_path}"
266 else
267 scm_module.create(repos_path)
268 end
235 end
269 end
236 rescue => e
270 rescue => e
237 log("\tunable to create #{repos_path} : #{e}\n")
271 log("\tunable to create #{repos_path} : #{e}\n")
General Comments 0
You need to be logged in to leave comments. Login now