ecb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -0
- data/bin/ecb +22 -0
- data/lib/commands.rb +22 -0
- data/lib/commands/commit.rb +91 -0
- data/lib/commands/configs.rb +58 -0
- data/lib/commands/format_helper.rb +106 -0
- data/lib/commands/make_sample.rb +85 -0
- data/lib/commands/periodic.rb +54 -0
- data/lib/commands/prepare.rb +191 -0
- data/lib/commands/prune.rb +53 -0
- data/lib/commands/pull.rb +140 -0
- data/lib/commands/push.rb +83 -0
- data/lib/commands/randombranch.rb +38 -0
- data/lib/commands/remove_merged_branches.rb +60 -0
- data/lib/commands/tag.rb +107 -0
- data/lib/commands/update_plist.rb +62 -0
- data/lib/commands/version.rb +33 -0
- data/lib/ebmsharedlib/monkey_patches.rb +33 -0
- data/lib/ebmsharedlib/options.rb +37 -0
- data/lib/ebmsharedlib/utilities.rb +234 -0
- data/lib/ecb.rb +169 -0
- data/lib/info.rb +12 -0
- data/lib/printer.rb +61 -0
- metadata +124 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
#
|
2
|
+
# Greg Seitz
|
3
|
+
#
|
4
|
+
# Copyright 2013, eBay Inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# http://www.ebay.com
|
7
|
+
#
|
8
|
+
module Commands
|
9
|
+
class Prepare
|
10
|
+
|
11
|
+
# holds the options that were passed
|
12
|
+
# you can set any initial defaults here
|
13
|
+
def options
|
14
|
+
@options ||= {
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# required options
|
19
|
+
def required_options
|
20
|
+
@required_options ||= Set.new [
|
21
|
+
:config,
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def register(opts, global_options)
|
26
|
+
opts.banner = "Usage: prepare [options]"
|
27
|
+
opts.description = "Prepare your build environment"
|
28
|
+
|
29
|
+
opts.on('-r', "--config-repo name", EbmSharedLib::REPO_COMMAND_DETAILS) do |v|
|
30
|
+
options[:config_repo] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-c', "--config name", "Required - Name of the config we are preparing from.") do |v|
|
34
|
+
options[:config] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-i', "--initials name", "Initials prepended to your branch For example --initials gws will result in something like gws_iphone_3.0.") do |v|
|
38
|
+
options[:initials] = v
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("--no-branch", "Don't create developer branch.") do |v|
|
42
|
+
options[:nobranch] = true # just indicate that the option was set (parms used --no to mean false but we don't want that)
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("--with-local-version", "Also include a local version branch, only applies with the -i option.") do |v|
|
46
|
+
options[:with_local_version] = true
|
47
|
+
end
|
48
|
+
opts.on('-n', "--shallow", "Checkout only level one to only have first level of history") do |v|
|
49
|
+
options[:shallow] = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# prepare a single repo and create a local and tracking branch if it should have one
|
54
|
+
# if the repo specifies a branch then we will do the initial fetch from that branch
|
55
|
+
# if the create_dev_branch flag is set, we will create a local and tracking branch with
|
56
|
+
# the developer initials prepended
|
57
|
+
def prepare_repo(repo, top_dir, initials, nobranch, with_local_version, shallow)
|
58
|
+
git_path = repo[:git_path]
|
59
|
+
branch = repo[:branch]
|
60
|
+
create_dev_branch = (repo[:create_dev_branch] == true) && (!nobranch)
|
61
|
+
tag = repo[:tag]
|
62
|
+
parent_path = repo[:parent_path]
|
63
|
+
|
64
|
+
if tag && branch
|
65
|
+
raise "We only support branching relative to HEAD, you cannot specify a branch:#{branch} and a tag:#{tag}."
|
66
|
+
end
|
67
|
+
|
68
|
+
if tag && create_dev_branch
|
69
|
+
raise "We do not support creating dev branches when using a tag"
|
70
|
+
end
|
71
|
+
|
72
|
+
# build the parent path if we have one and make it the new top dir
|
73
|
+
if parent_path
|
74
|
+
Dir.chdir(top_dir){
|
75
|
+
FileUtils.mkpath(parent_path)
|
76
|
+
}
|
77
|
+
top_dir = "#{top_dir}/#{parent_path}"
|
78
|
+
end
|
79
|
+
|
80
|
+
# first clone the repo
|
81
|
+
cmd = "git clone #{git_path} -b #{branch} #{shallow}"
|
82
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, top_dir) != 0
|
83
|
+
raise "Cloning repo at #{git_path} failed."
|
84
|
+
end
|
85
|
+
|
86
|
+
# extract the directory name that this repo ended up in
|
87
|
+
repo_name = EbmSharedLib.get_repo_name(git_path)
|
88
|
+
repo_path = "#{top_dir}/#{repo_name}"
|
89
|
+
|
90
|
+
# now set up the remote tracking base branch if we have one
|
91
|
+
if branch
|
92
|
+
cmd = "git checkout -B #{branch} --track origin/#{branch}"
|
93
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
94
|
+
raise "Checking out branch #{branch} for #{repo_name} failed."
|
95
|
+
end
|
96
|
+
|
97
|
+
# now create the developer branch off of the base branch
|
98
|
+
if create_dev_branch
|
99
|
+
dev_branch_name = "#{initials}_#{branch}"
|
100
|
+
# first assume dev branch already exists and try to switch to it
|
101
|
+
cmd = "git checkout --track origin/#{dev_branch_name}"
|
102
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
103
|
+
# no remote branch, so create local and push as remote
|
104
|
+
cmd = "git checkout -B #{dev_branch_name}"
|
105
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
106
|
+
raise "Unable to create local and tracking developer branch #{dev_branch_name} for #{repo_name}."
|
107
|
+
end
|
108
|
+
cmd = "git push -u origin #{dev_branch_name}"
|
109
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
110
|
+
raise "Unable to create local and tracking developer branch #{dev_branch_name} for #{repo_name}."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
if with_local_version == false
|
114
|
+
# they don't want the local version branch so drop it
|
115
|
+
cmd = "git branch -D #{branch}"
|
116
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
117
|
+
raise "Unable to delete local version branch #{branch} for #{repo_name}."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
elsif tag
|
122
|
+
# they are using a tag so don't create dev branches
|
123
|
+
cmd = "git checkout #{tag}"
|
124
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
125
|
+
raise "Unable to checkout tag:#{tag} for #{repo_name}."
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# pull any submodules
|
130
|
+
cmd = "git submodule init"
|
131
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
132
|
+
raise "Cloning submodules in repo at #{git_path} failed."
|
133
|
+
end
|
134
|
+
cmd = "git submodule update"
|
135
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
136
|
+
raise "Cloning submodules in repo at #{git_path} failed."
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def run(global_options)
|
142
|
+
|
143
|
+
# see if we can open the config file - we append the .config suffix
|
144
|
+
# the file is expected to be in JSON format
|
145
|
+
config_name = options[:config]
|
146
|
+
initials = options[:initials]
|
147
|
+
nobranch = !!options[:nobranch]
|
148
|
+
with_local_version = !!options[:with_local_version]
|
149
|
+
shallow = !!options[:shallow] ? "--depth=1" : ""
|
150
|
+
|
151
|
+
if (nobranch && initials)
|
152
|
+
raise "You must specify either the --initials or --no-branch, not both."
|
153
|
+
end
|
154
|
+
|
155
|
+
if (initials.nil? && nobranch == false)
|
156
|
+
raise "You must specify either --initials or --no-branch"
|
157
|
+
end
|
158
|
+
|
159
|
+
if (with_local_version && initials.nil?)
|
160
|
+
raise "Using --with-local-version is only applicable if you are also creating a developer branch -i."
|
161
|
+
end
|
162
|
+
|
163
|
+
# try to make sure the repo is available
|
164
|
+
config_repo = options[:config_repo]
|
165
|
+
config_repo_url = EbmSharedLib.prepare_config_repo(config_repo)
|
166
|
+
info = EbmSharedLib.read_repo_config(config_repo_url, config_name)
|
167
|
+
|
168
|
+
# Now that we have the json, prepare the world by creating a directory with the config name and placing
|
169
|
+
# the various repos beneath that. The directory is created relative to the current directory.
|
170
|
+
|
171
|
+
top_dir = "#{Dir.pwd}/#{config_name}"
|
172
|
+
raise "Cannot prepare since top level directory already exists: #{top_dir}" if File.directory?(top_dir)
|
173
|
+
|
174
|
+
Dir::mkdir(top_dir)
|
175
|
+
|
176
|
+
repos = info[:repos]
|
177
|
+
repos.each do |repo|
|
178
|
+
prepare_repo(repo, top_dir, initials, nobranch, with_local_version, shallow)
|
179
|
+
end
|
180
|
+
|
181
|
+
# finish up by writing settings
|
182
|
+
settings = {
|
183
|
+
:config_repo_url => config_repo_url,
|
184
|
+
:config_name => config_name,
|
185
|
+
}
|
186
|
+
EbmSharedLib.write_settings(settings, top_dir, err_msg = nil)
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Rick Hoiberg
|
3
|
+
#
|
4
|
+
# Copyright 2013, eBay Inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# http://www.ebay.com
|
7
|
+
#
|
8
|
+
module Commands
|
9
|
+
class Prune
|
10
|
+
|
11
|
+
# holds the options that were passed
|
12
|
+
# you can set any initial defaults here
|
13
|
+
def options
|
14
|
+
@options ||= {
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# required options
|
19
|
+
def required_options
|
20
|
+
@required_options ||= Set.new [
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def register(opts, global_options)
|
25
|
+
opts.banner = "Usage: prune"
|
26
|
+
opts.description = "Removes branches in the local repository that no longer exist on origin."
|
27
|
+
end
|
28
|
+
|
29
|
+
def run(global_options)
|
30
|
+
|
31
|
+
# see if we can open the config file - we append the .config suffix
|
32
|
+
# the file is expected to be in JSON format
|
33
|
+
|
34
|
+
# determine config_name by extracting parent of our directory
|
35
|
+
info = EbmSharedLib.get_config_from_top_dir
|
36
|
+
|
37
|
+
# Back up to version parent dir. This directory contains the top level repos.
|
38
|
+
top_dir = Dir.pwd
|
39
|
+
|
40
|
+
repos = info[:repos]
|
41
|
+
repos.each do |repo|
|
42
|
+
if repo[:create_dev_branch]
|
43
|
+
repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
|
44
|
+
repo_path = "#{top_dir}/#{repo_name}"
|
45
|
+
cmd = "git remote prune origin"
|
46
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
47
|
+
raise "Git push origin failed for #{repo_name}. Make sure you run the command from within a top level repo directory."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#
|
2
|
+
# Greg Seitz
|
3
|
+
#
|
4
|
+
# Copyright 2013, eBay Inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# http://www.ebay.com
|
7
|
+
#
|
8
|
+
module Commands
|
9
|
+
class Pull
|
10
|
+
|
11
|
+
# holds the options that were passed
|
12
|
+
# you can set any initial defaults here
|
13
|
+
def options
|
14
|
+
@options ||= {
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# required options
|
19
|
+
def required_options
|
20
|
+
@required_options ||= Set.new [
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def register(opts, global_options)
|
25
|
+
opts.banner = "Usage: pull [options]"
|
26
|
+
opts.description = "Pull code from remote repo."
|
27
|
+
|
28
|
+
opts.on('-t', "--tag name", "Name of the remote tag that you want to checkout. Warning this will overwrite any local changes.") do |v|
|
29
|
+
options[:tag] = v
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("--remote-version", "Pull from remote version branch into your current branch.") do |v|
|
33
|
+
options[:remote_version] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("--base-version", "Pull from base remote version branch into your current branch.") do |v|
|
37
|
+
options[:base_version] = true
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
|
41
|
+
options[:dry_run] = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [Object] global_options
|
46
|
+
def run(global_options)
|
47
|
+
|
48
|
+
# see if we can open the config file - we append the .config suffix
|
49
|
+
# the file is expected to be in JSON format
|
50
|
+
tag = options[:tag]
|
51
|
+
remote_version = !!options[:remote_version]
|
52
|
+
base_version = !!options[:base_version]
|
53
|
+
dry_run = !!options[:dry_run] ? "--dry-run" : ""
|
54
|
+
|
55
|
+
if ARGV.length > 0
|
56
|
+
raise "You must specify all arguments with their options."
|
57
|
+
end
|
58
|
+
|
59
|
+
if (!tag.nil? && (remote_version || base_version))
|
60
|
+
raise "You can't specify both a pull from a tag and a pull from a remote version branch together."
|
61
|
+
end
|
62
|
+
|
63
|
+
if (remote_version && base_version)
|
64
|
+
raise "You can only specify base-version or remote-version, not both."
|
65
|
+
end
|
66
|
+
|
67
|
+
# get config based on name of current dir
|
68
|
+
info = EbmSharedLib.get_config_from_top_dir
|
69
|
+
|
70
|
+
# Back up to version parent dir. This directory contains the top level repos.
|
71
|
+
top_dir = Dir.pwd
|
72
|
+
|
73
|
+
merge_failed = false
|
74
|
+
repos = info[:repos]
|
75
|
+
repos.each do |repo|
|
76
|
+
repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
|
77
|
+
repo_path = "#{top_dir}/#{repo_name}"
|
78
|
+
branch = repo[:branch]
|
79
|
+
base_branch = repo[:base_branch]
|
80
|
+
|
81
|
+
puts("\n#{repo_name} pull:\n");
|
82
|
+
|
83
|
+
cmd = "git fetch #{dry_run} --all"
|
84
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
85
|
+
raise "Git fetch failed for #{repo_name}."
|
86
|
+
end
|
87
|
+
|
88
|
+
if tag
|
89
|
+
# use git checkout to force changes from either tag or branch
|
90
|
+
cmd = "git checkout -f refs/tags/#{tag}"
|
91
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
92
|
+
raise "Git checkout failed for #{repo_name}."
|
93
|
+
end
|
94
|
+
elsif repo[:create_dev_branch]
|
95
|
+
if remote_version
|
96
|
+
# pulling from remote version branch
|
97
|
+
cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes origin #{branch}"
|
98
|
+
elsif base_version
|
99
|
+
# pulling from base remote version branch
|
100
|
+
if base_branch.nil?
|
101
|
+
raise "You specified base-version but the config has no base_branch."
|
102
|
+
end
|
103
|
+
cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes origin #{base_branch}"
|
104
|
+
else
|
105
|
+
# pull from the remote branch of the current branch
|
106
|
+
cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes"
|
107
|
+
end
|
108
|
+
|
109
|
+
exit_code = EbmSharedLib::CL.do_cmd_ignore_str(cmd, "Automatic merge failed", repo_path)
|
110
|
+
if exit_code != 0 && exit_code != 999
|
111
|
+
raise "Git pull failed for #{repo_name}."
|
112
|
+
end
|
113
|
+
if exit_code == 999
|
114
|
+
merge_failed = true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
cmd = "git submodule sync"
|
119
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
120
|
+
raise "Submodule sync for #{repo_name} failed."
|
121
|
+
end
|
122
|
+
if dry_run.empty?
|
123
|
+
cmd = "git submodule update"
|
124
|
+
else
|
125
|
+
cmd = "git submodule update --no-fetch"
|
126
|
+
end
|
127
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
128
|
+
raise "Updating submodules for #{repo_name} failed."
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
if merge_failed
|
134
|
+
raise "Automatic merge failed, you must hand merge the conflicts"
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#
|
2
|
+
# Greg Seitz
|
3
|
+
#
|
4
|
+
# Copyright 2013, eBay Inc.
|
5
|
+
# All rights reserved.
|
6
|
+
# http://www.ebay.com
|
7
|
+
#
|
8
|
+
module Commands
|
9
|
+
class Push
|
10
|
+
|
11
|
+
# holds the options that were passed
|
12
|
+
# you can set any initial defaults here
|
13
|
+
def options
|
14
|
+
@options ||= {
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# required options
|
19
|
+
def required_options
|
20
|
+
@required_options ||= Set.new [
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def register(opts, global_options)
|
25
|
+
opts.banner = "Usage: push [options]"
|
26
|
+
opts.description = "Push code to the remote repo."
|
27
|
+
|
28
|
+
opts.on("--remote-version", "Push from your local dev branch to the remote version branch - use with caution!") do |v|
|
29
|
+
options[:remote_version] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
|
33
|
+
options[:dry_run] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def run(global_options)
|
39
|
+
|
40
|
+
# see if we can open the config file - we append the .config suffix
|
41
|
+
# the file is expected to be in JSON format
|
42
|
+
remote_version = !!options[:remote_version]
|
43
|
+
dry_run = !!options[:dry_run] ? "--dry-run" : ""
|
44
|
+
|
45
|
+
if ARGV.length > 0
|
46
|
+
raise "You must specify all arguments with their options."
|
47
|
+
end
|
48
|
+
|
49
|
+
# get config based on name of current dir
|
50
|
+
info = EbmSharedLib.get_config_from_top_dir
|
51
|
+
|
52
|
+
# Back up to version parent dir. This directory contains the top level repos.
|
53
|
+
top_dir = Dir.pwd
|
54
|
+
|
55
|
+
repos = info[:repos]
|
56
|
+
repos.each do |repo|
|
57
|
+
if repo[:create_dev_branch]
|
58
|
+
repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
|
59
|
+
repo_path = "#{top_dir}/#{repo_name}"
|
60
|
+
local_branch = EbmSharedLib.get_current_branch(repo, repo_path)
|
61
|
+
|
62
|
+
puts("\n#{repo_name} push:\n");
|
63
|
+
|
64
|
+
if remote_version
|
65
|
+
# pulling from remote version branch
|
66
|
+
remote_branch = repo[:branch]
|
67
|
+
cmd = "git push #{dry_run} origin #{local_branch}:#{remote_branch}"
|
68
|
+
else
|
69
|
+
# pull from the remote branch of the current branch
|
70
|
+
# they want to commit whatever has changed and push to current remote
|
71
|
+
# first grab the current branch name
|
72
|
+
cmd = "git push #{dry_run} origin #{local_branch}"
|
73
|
+
end
|
74
|
+
if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
|
75
|
+
raise "Git push failed for #{repo_name}."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|