Class: Giternal::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/giternal/repository.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, name, repo_url, rel_path) ⇒ Repository

Returns a new instance of Repository.



10
11
12
13
14
15
16
# File 'lib/giternal/repository.rb', line 10

def initialize(base_dir, name, repo_url, rel_path)
  @base_dir = base_dir
  @name = name
  @repo_url = repo_url
  @rel_path = rel_path
  @verbose = self.class.verbose
end

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/giternal/repository.rb', line 6

def verbose
  @verbose
end

Instance Attribute Details

#verboseObject

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

Returns:

  • (Boolean)


61
62
63
# File 'lib/giternal/repository.rb', line 61

def checked_out?
  File.exist?(repo_path)
end

#freezifyObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/giternal/repository.rb', line 35

def freezify
  return true if frozen? || !checked_out?

  Dir.chdir(repo_path) do
    `tar czf .git.frozen.tgz .git`
     FileUtils.rm_r('.git')
  end
  `cd #{@base_dir} && git add -f #{rel_repo_path}`
  true
end

#frozen?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/giternal/repository.rb', line 57

def frozen?
  File.exist?(repo_path + '/.git.frozen.tgz')
end

#unfreezifyObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/giternal/repository.rb', line 46

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

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/giternal/repository.rb', line 18

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
      update_output { `cd #{repo_path} && git pull 2>&1` }
    end
  else
    update_output { `cd #{checkout_path} && git clone #{@repo_url} #{@name}` }
  end
  true
end