Class: GitSVNMirror
- Inherits:
-
Object
- Object
- GitSVNMirror
- Defined in:
- lib/git-svn-mirror.rb
Constant Summary collapse
- VERSION =
"0.1"
Instance Attribute Summary collapse
-
#authors_file ⇒ Object
Returns the value of attribute authors_file.
-
#from ⇒ Object
Returns the value of attribute from.
-
#silent ⇒ Object
Returns the value of attribute silent.
-
#to ⇒ Object
Returns the value of attribute to.
-
#workbench ⇒ Object
Returns the value of attribute workbench.
Class Method Summary collapse
- .init(mirror, argv) ⇒ Object
- .option_parser(mirror, argv) ⇒ Object
- .run(argv) ⇒ Object
- .update(mirror, argv) ⇒ Object
Instance Method Summary collapse
- #config(key) ⇒ Object
- #fetch ⇒ Object
- #init ⇒ Object
- #log(*str) ⇒ Object
- #push ⇒ Object
- #sh(command, capture = false) ⇒ Object
- #update ⇒ Object
Instance Attribute Details
#authors_file ⇒ Object
Returns the value of attribute authors_file.
6 7 8 |
# File 'lib/git-svn-mirror.rb', line 6 def @authors_file end |
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/git-svn-mirror.rb', line 6 def from @from end |
#silent ⇒ Object
Returns the value of attribute silent.
6 7 8 |
# File 'lib/git-svn-mirror.rb', line 6 def silent @silent end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/git-svn-mirror.rb', line 6 def to @to end |
#workbench ⇒ Object
Returns the value of attribute workbench.
6 7 8 |
# File 'lib/git-svn-mirror.rb', line 6 def workbench @workbench end |
Class Method Details
.init(mirror, argv) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/git-svn-mirror.rb', line 30 def self.init(mirror, argv) opts = option_parser(mirror, argv) do |o| o. = "Usage: git-svn-mirror init [mandatory options] [options]" o.separator "\n Mandatory options are --from and --to.\n\n" o.on('--from URI', 'The location of the SVN repository that is to be mirrored.') { |uri| mirror.from = uri } o.on('--to URI', 'The location of the GIT repository that is the mirror.') { |uri| mirror.to = uri } o.on('--workbench PATH', 'The location of the workbench repository. Defaults to the current work dir.') { |wb| mirror.workbench = wb } o.on('--authors-file PATH', 'An optional authors file used to migrate SVN usernames to GIT\'s format.') { |af| mirror. = af } end if mirror.from && mirror.to if !File.exist?(mirror.workbench) puts "[!] Given workbench path does not exist." false else if mirror. && !File.exist?(mirror.) puts "[!] Given authors file does not exist." false else mirror.init true end end else puts opts false end end |
.option_parser(mirror, argv) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/git-svn-mirror.rb', line 20 def self.option_parser(mirror, argv) opts = OptionParser.new do |o| yield(o) o.on('-s', '--silent', 'Silent mode.') { mirror.silent = true } o.on('-v', '--version', 'Print the version.') { puts VERSION; exit } end opts.parse!(argv) opts end |
.run(argv) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/git-svn-mirror.rb', line 8 def self.run(argv) mirror = new status = case argv.shift when 'init' then init(mirror, argv) when 'update' then update(mirror, argv) else puts "Usage: git-svn-mirror [init|update]" false end [mirror, status] end |
.update(mirror, argv) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/git-svn-mirror.rb', line 59 def self.update(mirror, argv) opts = option_parser(mirror, argv) do |o| o. = "Usage: git-svn-mirror update [options] [workbench1] [workbench2] ..." o.separator "\n Defaults to the current work dir if none is given.\n\n" end if argv.empty? mirror.update else argv.each do |workbench| mirror.workbench = workbench mirror.update end end true end |
Instance Method Details
#config(key) ⇒ Object
135 136 137 138 |
# File 'lib/git-svn-mirror.rb', line 135 def config(key) value = sh("git config --get #{key}", true) value unless value.empty? end |
#fetch ⇒ Object
101 102 103 104 |
# File 'lib/git-svn-mirror.rb', line 101 def fetch log "* Fetching from SVN repo at `#{from}'" sh "git svn fetch" end |
#init ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/git-svn-mirror.rb', line 76 def init log "* Configuring mirror workbench at `#{workbench}'" sh "git init --bare" sh "git svn init --stdlayout --prefix=svn/ #{from}" sh "git config --add svn.authorsfile '#{}'" if sh "git remote add origin #{to}" sh "git config --add remote.origin.push 'refs/remotes/svn/*:refs/heads/*'" fetch log "* Running garbage collection" sh "git gc" log "The mirror workbench has been configured. To push to the remote GIT repo,", "and possibly as a cron job, run the following command:", "", " $ git-svn-mirror update '#{workbench}'" end |
#log(*str) ⇒ Object
131 132 133 |
# File 'lib/git-svn-mirror.rb', line 131 def log(*str) puts("\n#{str.join("\n")}\n\n") unless @silent end |
#push ⇒ Object
106 107 108 109 |
# File 'lib/git-svn-mirror.rb', line 106 def push log "* Pushing to GIT repo at `#{to}'" sh "git push origin" end |
#sh(command, capture = false) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/git-svn-mirror.rb', line 140 def sh(command, capture = false) Dir.chdir(workbench) do command = "env GIT_DIR='#{workbench}' #{command}" command += (@silent ? " > /dev/null 2>&1" : " 1>&2") unless capture `#{command}`.strip end end |
#update ⇒ Object
96 97 98 99 |
# File 'lib/git-svn-mirror.rb', line 96 def update fetch push end |