Sha256: ed57e131d6560d3d55c462c502e5aad9310ff3fd88a7591ad260543ea776c9e0

Contents?: true

Size: 1.56 KB

Versions: 12

Compression:

Stored size: 1.56 KB

Contents

require "git"
require "fileutils"
require "pathname"

class ConfigGitCommit
    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}"
            if (Canzea::config[:track_changes_in_git])
                g = Git.init(gitRoot)
                g.add(:all=>true)
                g.commit("Original default #{sourcePath}")
            end
        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

        if (Canzea::config[:track_changes_in_git])
            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
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
canzea-0.1.107 lib/commands/config-git-commit.rb
canzea-0.1.106 lib/commands/config-git-commit.rb
canzea-0.1.105 lib/commands/config-git-commit.rb
canzea-0.1.104 lib/commands/config-git-commit.rb
canzea-0.1.103 lib/commands/config-git-commit.rb
canzea-0.1.102 lib/commands/config-git-commit.rb
canzea-0.1.101 lib/commands/config-git-commit.rb
canzea-0.1.100 lib/commands/config-git-commit.rb
canzea-0.1.98 lib/commands/config-git-commit.rb
canzea-0.1.97 lib/commands/config-git-commit.rb
canzea-0.1.96 lib/commands/config-git-commit.rb
canzea-0.1.95 lib/commands/config-git-commit.rb