Class: Giternal::Repository
- Inherits:
-
Object
- Object
- Giternal::Repository
- Defined in:
- lib/giternal/repository.rb
Class Attribute Summary collapse
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #checked_out? ⇒ Boolean
- #freezify ⇒ Object
- #frozen? ⇒ Boolean
-
#initialize(base_dir, name, repo_url, rel_path, branch = nil) ⇒ Repository
constructor
A new instance of Repository.
- #unfreezify ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(base_dir, name, repo_url, rel_path, branch = nil) ⇒ Repository
Returns a new instance of Repository.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/giternal/repository.rb', line 10 def initialize(base_dir, name, repo_url, rel_path, branch=nil) @base_dir = base_dir @name = name @repo_url = repo_url @rel_path = rel_path if branch != nil @branch = branch else @branch = "master" end @verbose = self.class.verbose end |
Class Attribute Details
.verbose ⇒ Object
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/giternal/repository.rb', line 6 def verbose @verbose end |
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/giternal/repository.rb', line 8 def verbose @verbose end |
Instance Method Details
#checked_out? ⇒ Boolean
70 71 72 |
# File 'lib/giternal/repository.rb', line 70 def checked_out? File.exist?(repo_path) end |
#freezify ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/giternal/repository.rb', line 44 def freezify return true if frozen? || !checked_out? Dir.chdir(repo_path) do `find .git | sort | xargs tar czf .git.frozen.tgz` FileUtils.rm_r('.git') end `cd #{@base_dir} && git add -f #{rel_repo_path}` true end |
#frozen? ⇒ Boolean
66 67 68 |
# File 'lib/giternal/repository.rb', line 66 def frozen? File.exist?(repo_path + '/.git.frozen.tgz') end |
#unfreezify ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/giternal/repository.rb', line 55 def unfreezify return true unless frozen? Dir.chdir(repo_path) do `tar xzf .git.frozen.tgz` FileUtils.rm('.git.frozen.tgz') end `cd #{@base_dir} && git rm -r --cached #{rel_repo_path}` true end |
#update ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/giternal/repository.rb', line 23 def update git_ignore_self return true if frozen? FileUtils.mkdir_p checkout_path unless File.exist?(checkout_path) if checked_out? if !File.exist?(repo_path + '/.git') raise "Directory '#{@name}' exists but is not a git repository" else current_branch = (`cd #{repo_path} && git branch`).split[1] if current_branch != @branch `cd #{repo_path} && git checkout #{@branch}` end update_output { `cd #{repo_path} && git pull 2>&1` } end else update_output { `cd #{checkout_path} && git clone #{@repo_url} #{@name} -b #{@branch}` } end true end |