Class: Svp::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/svp/workspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depot_uri, work_dir, svp_dir, revision, ignores) ⇒ Workspace

Returns a new instance of Workspace.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/svp/workspace.rb', line 11

def initialize(depot_uri, work_dir, svp_dir, revision, ignores)
  @depot_uri = depot_uri
  @work_dir = work_dir
  @svp_dir = svp_dir
  @revision = revision
  @ignores = ignores
  @base_dir = File.join(@svp_dir, "base")
  
  FileUtils.mkdir_p(@work_dir)
  FileUtils.mkdir_p(@base_dir)
end

Instance Attribute Details

#ignoresObject (readonly)

Returns the value of attribute ignores.



9
10
11
# File 'lib/svp/workspace.rb', line 9

def ignores
  @ignores
end

#revisionObject (readonly)

Returns the value of attribute revision.



9
10
11
# File 'lib/svp/workspace.rb', line 9

def revision
  @revision
end

Instance Method Details

#commit(*paths) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/svp/workspace.rb', line 23

def commit(*paths)
  changes = changes(paths)
  remote_exec do |p4|
    changes.each { |change| change.prepare_to_commit(p4) }
    puts "Transmitting file data ..."
    if p4.submit =~ /^Change (\d+) submitted./
      @revision = $1.to_i
      changes.each { |change| change.commit }
      puts "Committed revision #{@revision}."
    else
      changes.each { |change| change.rollback(p4) }
    end
  end
end

#delete(*files) ⇒ Object



38
39
40
41
42
43
# File 'lib/svp/workspace.rb', line 38

def delete(*files)
  files.each do |file|
    puts "D\t#{file}"
    FileUtils.rm_rf(file)
  end
end

#diff(*paths) ⇒ Object



45
46
47
# File 'lib/svp/workspace.rb', line 45

def diff(*paths)
  changes(paths).each { |change| change.diff }
end

#ignore(*patterns) ⇒ Object



49
50
51
# File 'lib/svp/workspace.rb', line 49

def ignore(*patterns)
  patterns.each { |pattern| @ignores << pattern }
end

#info(*remove_me) ⇒ Object



53
54
55
56
57
58
# File 'lib/svp/workspace.rb', line 53

def info(*remove_me)
  puts "Path: #{@work_dir}"
  puts "URL: #{@depot_uri}"
  puts "Revision: #{@revision}"
  puts "Ignores: #{@ignores.join(', ')}"
end

#revert(*paths) ⇒ Object



60
61
62
# File 'lib/svp/workspace.rb', line 60

def revert(*paths)
  changes(paths).each { |change| change.revert }
end

#status(*paths) ⇒ Object



64
65
66
67
68
# File 'lib/svp/workspace.rb', line 64

def status(*paths)
  changes(paths).each do |change|
    change.status
  end
end

#update(*remove_me) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/svp/workspace.rb', line 70

def update(*remove_me)
  if !changes.empty?
    puts "Local changes may cause conflicts"
    return
  end

  remote_exec do |p4|
    p4.changes("-m 1").scan(/^Change (\d+) on/) do |revision|
      revision = revision.first.to_i
      if @revision < revision
        p4.sync("@#{@revision.next},@#{revision}") 
        changes.each { |change| change.commit(p4) }
        @revision = revision
      end
    end
  end
  
  puts "At revision #{@revision}."
end