Class: Metabuild::Git
- Inherits:
-
Object
- Object
- Metabuild::Git
- Defined in:
- lib/metabuild.rb
Overview
Git access
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #apply_patch(patch) ⇒ Object
-
#cksum ⇒ Object
id is the SHA1 of head + of any diff (locals).
- #clone ⇒ Object
-
#get_diff ⇒ Object
Like running “git diff” in a git repo.
-
#initialize(dir = nil, path = nil) ⇒ Git
constructor
A new instance of Git.
- #inside_git_dir ⇒ Object
- #run(cmd) ⇒ Object
Constructor Details
#initialize(dir = nil, path = nil) ⇒ Git
Returns a new instance of Git.
89 90 91 |
# File 'lib/metabuild.rb', line 89 def initialize(dir = nil, path = nil) @path, @dir = path, dir end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
87 88 89 |
# File 'lib/metabuild.rb', line 87 def dir @dir end |
#path ⇒ Object
Returns the value of attribute path.
87 88 89 |
# File 'lib/metabuild.rb', line 87 def path @path end |
Instance Method Details
#apply_patch(patch) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/metabuild.rb', line 114 def apply_patch(patch) inside_git_dir do pipe = IO.popen("git apply -") pipe.puts patch pipe.close_write end end |
#cksum ⇒ Object
id is the SHA1 of head + of any diff (locals)
129 130 131 132 133 |
# File 'lib/metabuild.rb', line 129 def cksum inside_git_dir do `git log --pretty=format:'%H' | head -n 1`.to_i(16) ^ Digest::SHA1.hexdigest(get_diff).to_i(16) end end |
#clone ⇒ Object
122 123 124 125 126 |
# File 'lib/metabuild.rb', line 122 def clone raise "Cannot clone empty path" if @path.nil? @dir = pwd + File.basename(@path, ".git") if @dir.nil? run("clone #{@path} #{@dir}") end |
#get_diff ⇒ Object
Like running “git diff” in a git repo
102 103 104 105 106 |
# File 'lib/metabuild.rb', line 102 def get_diff inside_git_dir do `git diff` end end |
#inside_git_dir ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/metabuild.rb', line 93 def inside_git_dir raise "Directory not set for git repo #{@path}" if @dir.nil? or not File.exists? @dir old_dir = pwd cd dir yield cd old_dir end |
#run(cmd) ⇒ Object
108 109 110 111 112 |
# File 'lib/metabuild.rb', line 108 def run(cmd) inside_git_dir do raise "Git command #{cmd} failed in #{@path}" unless system("git #{cmd}") end end |