module Dev class Scm @@default=nil attr_accessor :scm_type def initialize puts_debug "initalizing Scm" call=Dev::SystemCall.new("svn info") @scm_type=nil @scm_type = "svn" if call.output.include?("Last Changed Date:") @scm_type = "svn" if @scm_type.nil? && File.exists?(".svn") if(@scm_type.nil?) call=Dev::SystemCall.new("git status") @scm_type = "git" if call.output.include?("#") @scm_type = "git" if @scm_type.nil? && File.exists?(".git") end puts_debug "scm_type = " + @scm_type.to_s end def file_tracked?(file) puts_debug "file_tracked?(" + file + ")" puts_debug "scm_type = #{@scm_type}" if @scm_type=="git" call=Dev::SystemCall.new("git ls-files #{file} --error-unmatch") puts_debug "call.output:" puts_debug call.output puts_debug "call.error" puts_debug call.error if call.status==0 puts_debug "file IS tracked by git." puts_debug call.output return true else puts_debug "file is NOT tracked by git." #return false end #return true if call.status==0 end #false end def add_file(file) #call=Dev::SystemCall.new("git add #{file}") if @scm_type=="git" if @scm_type=="svn" afile=file afile="#{file}@" if afile.include?('@') `svn info "#{afile}"` status=$?.exitstatus if(status != 0) call=Dev::SystemCall.new("svn add \"#{afile}\" --parents") call.puts_summary end end if @scm_type=="git" afile=file #`git status "#{afile}"` #status=$?.exitstatus #if(status != 0) if(file_tracked?(afile)) puts_debug "file #{afile} is tracked by git" else call=Dev::SystemCall.new("git add \"#{afile}\"") call.puts_summary end end end def add_file_glob(glob) Dir.glob(glob).each { |f| if(!f.include?("/obj/") && !f.include?("/bin/") && !f.include?("/TestOutput/") && f.index("obj/") != 0 && f.index("bin/") != 0 ) add_file(f) end } end def self.export(remote,local,scm) puts_debug "Scm.export, scm=#{scm}" if remote.include?("svn:") || scm=="svn" local_tmp=local.gsub('@','-') call=Dev::SystemCall.new("svn export \"#{remote}\" \"#{local_tmp}\"") call.puts_summary if(local_tmp != local) sleep 15 File.rename(local_tmp,local) if File.exist?(local_tmp) sleep 15 end end if scm=="git" call=Dev::SystemCall.new("git clone #{remote} #{local}") end end def self.update(local) end def self.get_default_scm_uri text=`svn info` if(!text.include?("not a working copy")) text.scan(/URL: ([\w:\/.-]+)/).each { |m| return m } end return nil end def self.get_default_scm_type if @@default.nil? puts_debug "creating default instance of Scm" @@default=Scm.new end return @@default.scm_type end end # class Scm end # module Dev