Class: StoreAgent::VersionManager::RubyGit

Inherits:
StoreAgent::VersionManager show all
Defined in:
lib/store_agent/version_manager/ruby_git.rb

Overview

ruby-git(github.com/schacon/ruby-git) を使用してバージョン管理を行うクラス
StoreAgent::VersionManager を継承しているので、詳細はそちらを参照

Instance Attribute Summary

Attributes inherited from StoreAgent::VersionManager

#workspace

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StoreAgent::VersionManager

#initialize

Constructor Details

This class inherits a constructor from StoreAgent::VersionManager

Class Method Details

.reserved_filenamesObject

:enddoc:



23
24
25
# File 'lib/store_agent/version_manager/ruby_git.rb', line 23

def self.reserved_filenames
  %w(.git .keep)
end

Instance Method Details

#add(*paths) ⇒ Object



35
36
37
38
39
40
# File 'lib/store_agent/version_manager/ruby_git.rb', line 35

def add(*paths)
  super do
    FileUtils.touch(paths)
    repository.add(paths, force: true)
  end
end

#initObject



27
28
29
30
31
32
33
# File 'lib/store_agent/version_manager/ruby_git.rb', line 27

def init
  super do
    Git.init
    repository.config["user.name"] || repository.config("user.name", "test_user")
    repository.config["user.email"] || repository.config("user.email", "[email protected]")
  end
end

#read(path: "", revision: nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/store_agent/version_manager/ruby_git.rb', line 71

def read(path: "", revision: nil)
  if path.end_with?("/")
    read_directory(path: path, revision: revision)
  else
    read_file(path: path, revision: revision)
  end
end

#remove(*paths, **_) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/store_agent/version_manager/ruby_git.rb', line 42

def remove(*paths, **_)
  super do
    # TODO fix
    paths_string = paths.map{|path| relative_path(path)}.join(" ")
    repository.chdir do
      `git rm --cached -f -r #{paths_string}`
    end
  end
end

#revisions(path = ".") ⇒ Object



79
80
81
# File 'lib/store_agent/version_manager/ruby_git.rb', line 79

def revisions(path = ".")
  logs(path).map(&:objectish)
end

#transaction(message) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/store_agent/version_manager/ruby_git.rb', line 52

def transaction(message)
  if @transaction
    yield
  else
    begin
      @transaction = true
      super do
        yield
      end
      repository.commit(message)
    rescue => e
      repository.reset_hard
      raise e
    ensure
      @transaction = false
    end
  end
end