Class: Dev::Scm

Inherits:
Object
  • Object
show all
Defined in:
lib/dev/Scm.rb

Constant Summary collapse

@@default =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScm

Returns a new instance of Scm.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dev/Scm.rb', line 7

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

Instance Attribute Details

#scm_typeObject

Returns the value of attribute scm_type.



5
6
7
# File 'lib/dev/Scm.rb', line 5

def scm_type
  @scm_type
end

Class Method Details

.export(remote, local, scm) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/dev/Scm.rb', line 85

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

.get_default_scm_typeObject



116
117
118
119
120
121
122
# File 'lib/dev/Scm.rb', line 116

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

.get_default_scm_uriObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/dev/Scm.rb', line 105

def self.get_default_scm_uri

  text=`svn info`
  if(!text.include?("not a working copy"))
 text.scan(/URL: ([\w:\/.-]+)/).each { |m|
   return m[0]
 }
  end
  return nil
end

.update(local) ⇒ Object



102
103
# File 'lib/dev/Scm.rb', line 102

def self.update(local)
end

Instance Method Details

#add_file(file) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dev/Scm.rb', line 43

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

#add_file_glob(glob) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dev/Scm.rb', line 73

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

#file_tracked?(file) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dev/Scm.rb', line 21

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