Class: Command::Checkout
Constant Summary collapse
- DETACHED_HEAD_MESSAGE =
<<~MSG You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using the branch command. Example: jit branch <new-branch-name> MSG
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Command::Base
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/command/checkout.rb', line 18 def run @target = @args[0] @current_ref = repo.refs.current_ref @current_oid = @current_ref.read_oid revision = Revision.new(repo, @target) @target_oid = revision.resolve(Revision::COMMIT) repo.index.load_for_update tree_diff = repo.database.tree_diff(@current_oid, @target_oid) migration = repo.migration(tree_diff) migration.apply_changes repo.index.write_updates repo.refs.set_head(@target, @target_oid) @new_ref = repo.refs.current_ref print_previous_head print_detachment_notice print_new_head exit 0 rescue Repository::Migration::Conflict handle_migration_conflict(migration) rescue Revision::InvalidObject => error handle_invalid_object(revision, error) end |