23
24
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/ding/cli.rb', line 23
def push
testing_branch = options[:branch] || Ding::TESTING_BRANCH.dup
develop_branch = Ding::DEVELOP_BRANCH.dup
if options[:skip]
say "\nDing ding ding: let's push the development branch to #{testing_branch}:\n\n", :green
else
say "\nDing ding ding: let's merge one or more feature branches to #{testing_branch}:\n\n", :green
end
repo = Ding::Git.new(options).tap do |r|
if r.is_dirty?
say "> Local repo is dirty, resetting state", :yellow
r.reset_local_state
end
r.checkout r.branch_in_context(develop_branch)
say "> Deleting #{testing_branch}", :green
r.delete_branch(testing_branch)
say "> Synchronising with the remote", :green
r.update
end
unless options[:skip]
branches = repo.remote_branches(options[:pattern])
if branches.empty?
say "\n --> No feature branches available to test, I'm out of here!\n\n", :red
exit 1
end
feature_branches = ask_which_item(branches, "\nWhich feature branch should I use?", :multiple)
say "\n"
end
original_commit_parents = repo.commit_parents(testing_branch)
repo.tap do |r|
say "> Deleting any synched #{testing_branch}", :green
r.delete_branch(testing_branch)
say "> Creating #{testing_branch} from #{develop_branch}", :green
r.create_branch(testing_branch)
unless options[:skip]
say "> Merging in selected feature #{feature_branches.count == 1 ? 'branch' : 'branches'}...", :green
merge_errors = false
feature_branches.each do |branch|
if r.merge_branch(branch)
say " ✓ #{branch}", :green
else
say " ✗ #{branch}", :red
merge_errors = true
end
end
end
unless merge_errors
say "> Pushing #{testing_branch} to the remote", :green
r.push(testing_branch)
else
say "\n --> There were merge errors, ding dang it!\n\n", :red
exit 1
end
if original_commit_parents &&
(remote_commit_parents = repo.commit_parents(testing_branch)) &&
remote_commit_parents.sort == original_commit_parents.sort
result = options[:verbose] ? ": #{original_commit_parents}" : ''
say "\n --> That did not alter the testing branch commit parents#{result}!\n", :yellow
end
end
rescue => e
show_error e
else
say "\n --> I'm finished: ding ding ding!\n\n", :green
exit 0
end
|