Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial stab at enabling git submodule support in between meals #18

Closed
wants to merge 9 commits into from
4 changes: 4 additions & 0 deletions lib/between_meals/changes/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def self.explode_path(path, cookbook_dirs)
re = %r{^#{dir}/([^/]+)/.*}
debug("[cookbook] Matching #{path} against ^#{re}")
m = path.match(re)
if !m
debug("[cookbook] (retry) Matching #{path} against ^#{re}")
m = "#{path}/".match(re)
end
next unless m
info("Cookbook is #{m[1]}")
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/between_meals/knife.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def databag_upload(databags)
dbitems = dbs.map do |x|
File.join(@databag_dir, dbname, "#{x.item}.json")
end.join(' ')
exec!("#{@knife} data bag from file #{dbname} #{dbitems}", @logger)
exec!("#{@knife} data bag from file #{dbname} #{dbitems} -c #{config}", @logger)
end
end
end
Expand Down
27 changes: 16 additions & 11 deletions lib/between_meals/repo/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def head_parents

def checkout(url)
s = Mixlib::ShellOut.new(
"#{@bin} clone #{url} #{@repo} #{@repo_path}"
"#{@bin} clone --recurse-submodules #{url} #{@repo} #{@repo_path}"
).run_command
s.error!
@repo = Rugged::Repository.new(File.expand_path(@repo_path))
Expand Down Expand Up @@ -93,16 +93,21 @@ def changes(start_ref, end_ref)
end

def update
cmd = Mixlib::ShellOut.new(
"#{@bin} pull --rebase", :cwd => File.expand_path(@repo_path)
)
cmd.run_command
if cmd.exitstatus != 0
@logger.error('Something went wrong with git!')
@logger.error(cmd.stdout)
fail
cmds = ["#{@bin} pull --rebase --recurse-submodules", "#{@bin} submodule update --init --recursive"]
stdout = ""
cmds.each do |cmd|
cmd = Mixlib::ShellOut.new(
"#{@bin} pull --rebase --recurse-submodules", :cwd => File.expand_path(@repo_path)
)
cmd.run_command
if cmd.exitstatus != 0
@logger.error('Something went wrong with git!')
@logger.error(cmd.stdout)
fail
end
stdout = stdout + cmd.stdout
end
cmd.stdout
stdout
end

# Return all files
Expand Down Expand Up @@ -168,7 +173,7 @@ def parse_status(changes)
# X: "unknown" change type (most probably a bug, please report it)

# rubocop:disable MultilineBlockChain
changes.lines.map do |line|
changes.lines.to_a.reverse.map do |line|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To handle the case of a path being removed and re-added as a submodule. Before reversing the order it was only picking up the delete, and not the addition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide an example git output? And incorporate that into the test cases? I've got a feeling this fix is incidental and possibly breaking other stuff.

case line
when /^A\s+(\S+)$/
# A path
Expand Down