Top Level Namespace
Defined Under Namespace
Modules: TwoRingToolError
Instance Method Summary
collapse
Instance Method Details
#echo_and_exec(command) ⇒ Object
1
2
3
4
|
# File 'lib/echoexec.rb', line 1
def echo_and_exec command
puts command
`#{command}`
end
|
#git_check ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/git_check.rb', line 4
def git_check
modified_file_count, stderr, status = Open3.capture3("git status --porcelain | egrep '^(M| M)' | wc -l")
if modified_file_count.to_i > 0 then
puts 'Please commit all changes to working index before proceeding.'
exit TwoRingToolError::GIT_DIRTY_INDEX
end
end
|
#sync_fork(forked_repo_info, root_dir_path) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/git_helpers.rb', line 25
def sync_fork forked_repo_info, root_dir_path
upstream_ssh_url = forked_repo_info.source.ssh_url
original_owner = forked_repo_info.source.owner.login
name = forked_repo_info.name
fork_ssh_url = forked_repo_info.ssh_url
upstream_remote_name = 'upstream'
fork_remote_name = 'fork'
path = "#{root_dir_path}/_Forks/#{original_owner}/#{name}"
already_cloned = Dir.exist?(path)
unless already_cloned then
echo_and_exec "git clone #{fork_ssh_url} #{path}"
end
Dir.chdir path do
unless already_cloned then
echo_and_exec "git remote add #{upstream_remote_name} #{upstream_ssh_url}"
echo_and_exec "git remote rename origin #{fork_remote_name}"
end
fork_default_branch_name = `git remote show #{fork_remote_name} | grep "HEAD branch" | cut -d ":" -f 2`.strip
fork_default_local_branch_name = "#{fork_remote_name}_#{fork_default_branch_name}"
upstream_default_branch_name = `git remote show #{upstream_remote_name} | grep "HEAD branch" | cut -d ":" -f 2`.strip
upstream_default_local_branch_name = "#{upstream_remote_name}_#{upstream_default_branch_name}"
unless already_cloned then
echo_and_exec "git branch -m #{fork_default_branch_name} #{fork_default_local_branch_name}"
echo_and_exec "git fetch #{upstream_remote_name}"
echo_and_exec "git checkout -b #{upstream_default_local_branch_name} #{upstream_remote_name}/#{upstream_default_branch_name}"
echo_and_exec "git push #{fork_remote_name} HEAD:#{upstream_default_local_branch_name}"
end
if already_cloned then
echo_and_exec "git checkout #{fork_default_local_branch_name}"
echo_and_exec "git pull --ff-only #{fork_remote_name}"
echo_and_exec "git fetch --tags #{fork_remote_name}"
echo_and_exec "git checkout #{upstream_default_local_branch_name}"
echo_and_exec "git pull --ff-only #{upstream_remote_name}"
end
end
end
|
#sync_repo(repo_info, root_dir_path) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/git_helpers.rb', line 4
def sync_repo repo_info, root_dir_path
name = repo_info.name
ssh_url = repo_info.ssh_url
path = "#{root_dir_path}/#{name}"
already_cloned = Dir.exist?(path)
unless already_cloned then
echo_and_exec "git clone #{ssh_url} #{path}"
end
if already_cloned then
Dir.chdir path do
echo_and_exec "git fetch && git fetch --tags && git pull --ff-only"
end
end
end
|