require 'rubygems'
require 'provisional/repo_man'
require 'provisional/scm/git'

module Provisional
  module SCM
    class RepoManGit < Provisional::SCM::Git
      def initialize(options)
        raise ArgumentError, "domain must be specified" unless options['domain']
        super
      end

      def checkin
        begin
          repo = super
          RepoMan::Repository.site = "http://repoman.#{@options['domain']}/"
          RepoMan::Repository.create(:name => @options['name'], :scm => 'git')
          repo.add_remote('origin', "git.#{@options['domain']}:/srv/git/#{@options['name']}.git")
          repo.push
        rescue
          raise RuntimeError, "Repository created locally, but not pushed to Repo Man due to exception: #{$!}"
        end
      end
    end
  end
end