lib/fulmar/domain/service/dependency_service.rb in fulmar-1.8.5 vs lib/fulmar/domain/service/dependency_service.rb in fulmar-1.8.6
- old
+ new
@@ -32,11 +32,11 @@
def update(env = @config.environment)
@config.dependencies(env).each_pair do |_key, data|
next unless data[:type].blank? || data[:type] == 'git'
git = Rugged::Repository.new(data[:path])
- checkout(git, data)
+ handle_uncommitted_changes(git, data)
# Pull
shell = Fulmar::Infrastructure::Service::ShellService.new data[:path]
unless shell.run 'git pull --rebase -q'
fail "Cannot update repository #{data[:path]}. Please update manually."
@@ -44,10 +44,37 @@
end
end
protected
+ ##
+ # Runs a defined update policy to avoid git conflicts
+ # @param git [Rugged::Repository]
+ # @param dependency [Hash]
+ def handle_uncommitted_changes(git, dependency)
+ policy = dependency[:update_policy] || ''
+
+ case policy
+ when 'reset'
+ reset(git)
+ when -> (p) { p.nil? || p.empty? }
+ puts 'No update policy configured'
+ else
+ puts "Unexpected update policy #{policy}"
+ end
+ end
+
+ ##
+ # Reset changes
+ # @param git [Rugged::Repository]
+ def reset(git)
+ head = git.head
+ git.reset(head.target_id, :hard) unless head.nil?
+ end
+
def checkout(git, dependency)
+ handle_uncommitted_changes(git, dependency)
+
# Switch to the configured branch/tag/commit
if git.branches.select { |b| b.name.split('/').last == dependency[:ref] }.any?
checkout_branch(git, dependency[:ref])
elsif git.tags.map(&:name).include?(dependency[:ref])
git.checkout("refs/tags/#{dependency[:ref]}")