Module: DeepThought::Git
- Defined in:
- lib/deep_thought/git.rb
Defined Under Namespace
Classes: GitBranchNotFoundError, GitRepositoryNotFoundError
Class Method Summary
collapse
Class Method Details
.get_latest_commit_for_branch(project, branch) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/deep_thought/git.rb', line 44
def self.get_latest_commit_for_branch(project, branch)
self.clone_if_not_exists(project)
system "cd ./.projects/#{project.name} && git fetch -p > /dev/null 2>&1"
repo = Rugged::Repository.new(".projects/#{project.name}")
switch_to_branch(project, branch)
repo.head.target
end
|
.get_list_of_branches(project) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/deep_thought/git.rb', line 30
def self.get_list_of_branches(project)
self.clone_if_not_exists(project)
system "cd ./.projects/#{project.name} && git fetch -p > /dev/null 2>&1"
repo = Rugged::Repository.new(".projects/#{project.name}")
branches = Rugged::Branch.each_name(repo, :remote).sort
branches.map! { |x| x.sub!('origin/', '') }
branches.delete('HEAD')
branches
end
|
.setup(project) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/deep_thought/git.rb', line 8
def self.setup(project)
if !File.directory?(".projects/#{project.name}/.git")
exit_status = system "git clone #{project.repo_url} .projects/#{project.name} > /dev/null 2>&1"
if exit_status
if !File.directory?(".projects/#{project.name}/.git")
false
else
if Dir.entries(".projects/#{project.name}") == [".", "..", ".git"]
false
else
true
end
end
else
false
end
else
true
end
end
|
.switch_to_branch(project, branch) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/deep_thought/git.rb', line 56
def self.switch_to_branch(project, branch)
self.clone_if_not_exists(project)
exit_status = system "cd ./.projects/#{project.name} && git fetch -p > /dev/null 2>&1 && git reset --hard origin/#{branch} > /dev/null 2>&1"
if exit_status
true
else
raise GitBranchNotFoundError, "#{project.name} doesn't appear to have a branch called #{branch}. Have you pushed it?"
end
end
|