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, 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

.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)


70
71
72
# File 'lib/giternal/repository.rb', line 70

def checked_out?
  File.exist?(repo_path)
end

#freezifyObject



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

Returns:

  • (Boolean)


66
67
68
# File 'lib/giternal/repository.rb', line 66

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

#unfreezifyObject



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

#updateObject



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