Module: Dply::Git
- Extended by:
- Helper
- Defined in:
- lib/dply/git.rb
Class Method Summary
collapse
Methods included from Helper
cmd, error, git, logger, sh, symlink
Class Method Details
.checkout(branch) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/dply/git.rb', line 17
def self.checkout(branch)
current_branch = `git rev-parse --abbrev-ref HEAD `.chomp
return if branch == current_branch
local_branch_exists = system "git", "show-ref", "-q", "--verify", "refs/heads/#{branch}"
if local_branch_exists
cmd "git checkout #{branch} --"
else
cmd "git checkout -b #{branch} -t origin/#{branch}"
end
end
|
.clean ⇒ Object
38
39
40
41
|
# File 'lib/dply/git.rb', line 38
def self.clean
cmd "git reset --hard HEAD"
cmd "git clean -dxf "
end
|
.clone(repo, dir, mirror: nil) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/dply/git.rb', line 29
def self.clone(repo, dir, mirror: nil)
if mirror
cmd "git clone #{mirror} #{dir}"
Dir.chdir(dir) { cmd "git remote set-url origin #{repo}" }
else
cmd "git clone #{repo} #{dir}"
end
end
|
.commit_id ⇒ Object
59
60
61
62
63
|
# File 'lib/dply/git.rb', line 59
def self.commit_id
commit_id = cmd "git rev-parse HEAD", return_output: true, display: false
logger.debug commit_id.chomp
commit_id.chomp
end
|
.pull(branch) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/dply/git.rb', line 7
def self.pull(branch)
cmd "git fetch"
checkout(branch)
if tracking_branch = tracking_branch(branch)
cmd "git merge #{tracking_branch}"
else
cmd "git pull origin #{branch}"
end
end
|
.remote_url ⇒ Object
53
54
55
56
57
|
# File 'lib/dply/git.rb', line 53
def self.remote_url
remote_url = cmd "git config --get remote.origin.url", return_output: true, display: false
logger.debug remote_url.chomp
remote_url.chomp
end
|
.tracking_branch(branch) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/dply/git.rb', line 43
def self.tracking_branch(branch)
command = "git for-each-ref --format='%(upstream:short)' refs/heads/#{branch} --count=1"
tracking_branch = cmd command, return_output: true, display: false
if tracking_branch =~ /[a-zA-Z0-9_]/
return tracking_branch.chomp!
else
return nil
end
end
|