Class: ConfigGitCommit

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/config-git-commit.rb

Instance Method Summary collapse

Instance Method Details

#do(gitRoot, sourcePath, template, parameters) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/commands/config-git-commit.rb', line 6

def do(gitRoot, sourcePath, template, parameters)
    # if file exists on file system and does not exist in gitRoot, then commit the "oem" file

    if (File.exists?(sourcePath))
        dest = "#{gitRoot}/config#{Pathname.new(sourcePath).realpath}"
    else
        dest = "#{gitRoot}/config#{sourcePath}"
    end
    puts "Writing to #{dest}"

    if (File.exist?(dest) == false and File.exist?(sourcePath))
        FileUtils.mkdir_p Pathname.new(dest).dirname
        FileUtils.cp sourcePath, dest

        puts "Recording in repo the default file first: #{sourcePath}"
        g = Git.init(gitRoot)
        g.add(:all=>true)
        g.commit("Original default #{sourcePath}")
    end

    if template
        puts "Processing template #{template}"
        FileUtils.mkdir_p Pathname.new(sourcePath).dirname
        t = Template.new
        t.processAndWriteToFile template, sourcePath, parameters
    end
    FileUtils.mkdir_p Pathname.new(dest).dirname
    FileUtils.cp sourcePath, dest

    g = Git.init(gitRoot)
    g.add(:all=>true)
    puts g.status.changed.size() + g.status.added.size()
    if (g.status.changed.size() > 0 or g.status.added.size() > 0)
        g.commit("Config update #{sourcePath}")
    end
end