lib/braid/commands/update.rb in dreamcat4-braid-0.50 vs lib/braid/commands/update.rb in dreamcat4-braid-0.52

- old
+ new

@@ -18,76 +18,81 @@ end end def update_one(path, options = {}) mirror = config.get!(path) - + revision_message = options["revision"] ? " to #{display_revision(mirror, options["revision"])}" : "" msg "Updating mirror '#{mirror.path}'#{revision_message}." - # check options for lock modification - if mirror.locked? - if options["head"] - msg "Unlocking mirror '#{mirror.path}'." if verbose? - mirror.lock = nil - elsif !options["revision"] - msg "Mirror '#{mirror.path}' is locked to #{display_revision(mirror, mirror.lock)}. Use --head to force." - return + if mirror.type == "git-clone" + mirror.rspec_git.update options["revision"] + else + + # check options for lock modification + if mirror.locked? + if options["head"] + msg "Unlocking mirror '#{mirror.path}'." if verbose? + mirror.lock = nil + elsif !options["revision"] + msg "Mirror '#{mirror.path}' is locked to #{display_revision(mirror, mirror.lock)}. Use --head to force." + return + end end - end - setup_remote(mirror) - msg "Fetching new commits for '#{mirror.path}'." if verbose? - mirror.fetch + setup_remote(mirror) + msg "Fetching new commits for '#{mirror.path}'." if verbose? + mirror.fetch - new_revision = validate_new_revision(mirror, options["revision"]) - target_revision = determine_target_revision(mirror, new_revision) + new_revision = validate_new_revision(mirror, options["revision"]) + target_revision = determine_target_revision(mirror, new_revision) - if mirror.merged?(target_revision) - msg "Mirror '#{mirror.path}' is already up to date." - return - end + if mirror.merged?(target_revision) + msg "Mirror '#{mirror.path}' is already up to date." + return + end - if mirror.squashed? - diff = mirror.diff - base_revision = mirror.base_revision - end + if mirror.squashed? + diff = mirror.diff + base_revision = mirror.base_revision + end - mirror.revision = new_revision - mirror.lock = new_revision if options["revision"] + mirror.revision = new_revision + mirror.lock = new_revision if options["revision"] - msg "Merging in mirror '#{mirror.path}'." if verbose? - begin - if mirror.squashed? - local_hash = git.rev_parse("HEAD") - if diff - base_hash = generate_tree_hash(mirror, base_revision) + msg "Merging in mirror '#{mirror.path}'." if verbose? + begin + if mirror.squashed? + local_hash = git.rev_parse("HEAD") + if diff + base_hash = generate_tree_hash(mirror, base_revision) + else + base_hash = local_hash + end + remote_hash = generate_tree_hash(mirror, target_revision) + ENV["GITHEAD_#{local_hash}"] = "HEAD" + ENV["GITHEAD_#{remote_hash}"] = target_revision + git.merge_recursive(base_hash, local_hash, remote_hash) else - base_hash = local_hash + git.merge_subtree(target_revision) end - remote_hash = generate_tree_hash(mirror, target_revision) - ENV["GITHEAD_#{local_hash}"] = "HEAD" - ENV["GITHEAD_#{remote_hash}"] = target_revision - git.merge_recursive(base_hash, local_hash, remote_hash) - else - git.merge_subtree(target_revision) + rescue Operations::MergeError => error + msg "Caught merge error. Breaking." end - rescue Operations::MergeError => error - msg "Caught merge error. Breaking." - end - config.update(mirror) - add_config_file + config.update(mirror) + add_config_file - commit_message = "Updated mirror '#{mirror.path}' to #{display_revision(mirror)}" + commit_message = "Updated mirror '#{mirror.path}' to #{display_revision(mirror)}" - if error - File.open(".git/MERGE_MSG", 'w') { |f| f.puts(commit_message) } - return - end + if error + File.open(".git/MERGE_MSG", 'w') { |f| f.puts(commit_message) } + return + end - git.commit(commit_message) - msg commit_message + git.commit(commit_message) + msg commit_message + end end def generate_tree_hash(mirror, revision) git.rm_r(mirror.path) git.read_tree_prefix(revision, mirror.path)