Class: Dev::Scm

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScm

Returns a new instance of Scm.



5
6
7
8
9
10
11
12
13
# File 'lib/dev/Scm.rb', line 5

def initialize
  @scm_type="none"
	call=Dev::SystemCall.new("svn info")
	@scm_type="svn" if call.output.include?("Last Changed Date:")
  @scm_type="svn" if File.exists?(".svn")
	call=Dev::SystemCall.new("git status")
	@scm_type="git" if call.output.include?("#")
  @scm_type="git" if File.exists?(".git")
end

Instance Attribute Details

#scm_typeObject

Returns the value of attribute scm_type.



3
4
5
# File 'lib/dev/Scm.rb', line 3

def scm_type
  @scm_type
end

Class Method Details

.export(remote, local, scm) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/dev/Scm.rb', line 79

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

.update(local) ⇒ Object



96
97
# File 'lib/dev/Scm.rb', line 96

def self.update(local)
end

Instance Method Details

#add_file(file) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dev/Scm.rb', line 37

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



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dev/Scm.rb', line 67

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)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dev/Scm.rb', line 15

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