lib/braid/commands/update.rb in braid-1.0.17 vs lib/braid/commands/update.rb in braid-1.0.18

- old
+ new

@@ -15,28 +15,39 @@ update_one(path, options) end end def update_one(path, options = {}) + bail_on_local_changes! + + raise BraidError, "Do not specify --head option anymore. Please use '--branch MyBranch' to track a branch or '--tag MyTag' to track a branch" if options['head'] + mirror = config.get!(path) - revision_message = options['revision'] ? " to #{display_revision(mirror, options['revision'])}" : '' - msg "Updating mirror '#{mirror.path}'#{revision_message}." + msg "Updating mirror '#{mirror.path}'." was_locked = mirror.locked? + original_revision = mirror.revision + original_branch = mirror.branch + original_tag = mirror.tag - # 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 + raise BraidError, 'Can not update mirror specifying both a revision and a tag' if options['revision'] && options['tag'] + raise BraidError, 'Can not update mirror specifying both a branch and a tag' if options['branch'] && options['tag'] + + if options['tag'] + mirror.tag = options['tag'] + mirror.branch = nil + elsif options['branch'] + mirror.tag = nil + mirror.branch = options['branch'] + elsif options['revision'] + mirror.tag = nil + mirror.branch = nil end + config.update(mirror) + setup_remote(mirror) msg "Fetching new commits for '#{mirror.path}'." if verbose? mirror.fetch new_revision = options['revision'] @@ -46,20 +57,38 @@ # Ignored as it means the revision matches expected end target_revision = determine_target_revision(mirror, new_revision) current_revision = determine_target_revision(mirror, mirror.base_revision) - if (options['revision'] && was_locked && target_revision == current_revision) || - (options['revision'].nil? && !was_locked && mirror.merged?(git.rev_parse(new_revision))) + from_desc = + original_tag ? "tag '#{original_tag}'" : + !was_locked ? "branch '#{original_branch}'" : + "revision '#{original_revision}'" + + switching = true + if mirror.branch && (original_branch != mirror.branch || (was_locked && !mirror.locked?)) + msg "Switching mirror '#{mirror.path}' to branch '#{mirror.branch}' from #{from_desc}." + elsif mirror.tag && original_tag != mirror.tag + msg "Switching mirror '#{mirror.path}' to tag '#{mirror.tag}' from #{from_desc}." + elsif options['revision'] && original_revision != options['revision'] + msg "Switching mirror '#{mirror.path}' to revision '#{options['revision']}' from #{from_desc}." + else + switching = false + end + + if !switching && + ( + (options['revision'] && was_locked && target_revision == current_revision) || + (options['revision'].nil? && !was_locked && mirror.merged?(git.rev_parse(new_revision))) + ) msg "Mirror '#{mirror.path}' is already up to date." clear_remote(mirror, options) return end base_revision = mirror.base_revision mirror.revision = new_revision - mirror.lock = new_revision if options['revision'] msg "Merging in mirror '#{mirror.path}'." if verbose? in_error = false begin local_hash = git.rev_parse('HEAD')