Module: Docman::GitUtil
- Defined in:
- lib/docman/git_util.rb
Class Method Summary collapse
- .commit(root_path, path, message, tag = nil) ⇒ Object
- .exec(command) ⇒ Object
- .get(repo, path, type, version) ⇒ Object
- .last_commit_hash(path, branch) ⇒ Object
- .last_revision ⇒ Object
- .pull(path) ⇒ Object
- .push(root_path, version) ⇒ Object
- .read_yaml_from_file(repo, path, version, filename) ⇒ Object
- .repo?(path) ⇒ Boolean
- .repo_changed?(path) ⇒ Boolean
- .reset_repo(path) ⇒ Object
- .tag(root_path, tag) ⇒ Object
- .update(path) ⇒ Object
Class Method Details
.commit(root_path, path, message, tag = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/docman/git_util.rb', line 64 def self.commit(root_path, path, , tag = nil) if repo_changed? path # puts message pull root_path exec %Q(git add --all #{path.slice "#{root_path}/"}) exec %Q(git commit -m "#{message}") if repo_changed? path self.tag(root_path, tag) if tag end end |
.exec(command) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/docman/git_util.rb', line 9 def self.exec(command) @logger.info command result = `#{command}`.delete!("\n") @logger.info result if result raise "ERROR: #{result}" unless $?.exitstatus == 0 result end |
.get(repo, path, type, version) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/docman/git_util.rb', line 23 def self.get(repo, path, type, version) if File.directory? path and File.directory?(File.join(path, '.git')) Dir.chdir path self.reset_repo(path) #if self.repo_changed?(path) if type == 'branch' exec "git fetch" exec "git checkout #{version}" exec "git pull origin #{version}" end if type == 'tag' exec 'git fetch --tags' exec "git checkout tags/#{version}" end else FileUtils.rm_rf path if File.directory? path exec "git clone #{repo} #{path}" Dir.chdir path exec "git checkout #{version}" end result = type == 'branch' ? self.last_revision : version result end |
.last_commit_hash(path, branch) ⇒ Object
87 88 89 90 91 |
# File 'lib/docman/git_util.rb', line 87 def self.last_commit_hash(path, branch) Dir.chdir path result = `git rev-parse --short origin/#{branch}` result.delete!("\n") end |
.last_revision ⇒ Object
55 56 57 58 |
# File 'lib/docman/git_util.rb', line 55 def self.last_revision result = `git rev-parse --short HEAD` result.delete!("\n") end |
.pull(path) ⇒ Object
74 75 76 77 |
# File 'lib/docman/git_util.rb', line 74 def self.pull(path) Dir.chdir path exec 'git pull' end |
.push(root_path, version) ⇒ Object
93 94 95 96 97 |
# File 'lib/docman/git_util.rb', line 93 def self.push(root_path, version) Dir.chdir root_path exec "git pull origin #{version}" exec "git push origin #{version}" end |
.read_yaml_from_file(repo, path, version, filename) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/docman/git_util.rb', line 46 def self.read_yaml_from_file(repo, path, version, filename) self.get(repo, path, 'branch', version) filepath = File.join(path, filename) return YAML::load_file(filepath) if File.file? filepath nil rescue StandardError => e raise "Error in info file: #{filepath}, #{e.message}" end |
.repo?(path) ⇒ Boolean
79 80 81 |
# File 'lib/docman/git_util.rb', line 79 def self.repo?(path) File.directory? File.join(path, '.git') end |
.repo_changed?(path) ⇒ Boolean
83 84 85 |
# File 'lib/docman/git_util.rb', line 83 def self.repo_changed?(path) not Exec.do "#{Application::bin}/dm_repo_clean.sh #{path}" end |
.reset_repo(path) ⇒ Object
17 18 19 20 21 |
# File 'lib/docman/git_util.rb', line 17 def self.reset_repo(path) Dir.chdir path exec 'git reset --hard' exec 'git clean -f -d' end |
.tag(root_path, tag) ⇒ Object
99 100 101 102 103 |
# File 'lib/docman/git_util.rb', line 99 def self.tag(root_path, tag) Dir.chdir root_path exec %Q(git tag -a -m "Tagged to #{tag}" "#{tag}") exec "git push origin #{tag}" end |
.update(path) ⇒ Object
60 61 62 |
# File 'lib/docman/git_util.rb', line 60 def self.update(path) pull path end |