Module: Git::Repository::Committing
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/committing.rb
Overview
Facade methods for committing operations: recording commits, manipulating tree objects, and building commit objects outside the working tree
Included by Git::Repository.
Instance Method Summary collapse
-
#commit(message, opts = {}) ⇒ String
Record staged changes as a new commit.
-
#commit_all(message, opts = {}) ⇒ String
Commit all modified tracked files without explicitly staging them first.
-
#commit_tree(tree = nil, opts = {}) ⇒ String
Create a commit object from a tree SHA without moving HEAD.
-
#write_and_commit_tree(opts = {}) ⇒ String
Write the current index to a tree object and immediately commit it.
-
#write_tree ⇒ String
Write the current index to a tree object in the object store.
Instance Method Details
#commit(message, opts = {}) ⇒ String
Record staged changes as a new commit
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/git/repository/committing.rb', line 75 def commit(, opts = {}) opts = opts.dup if opts.key?(:add_all) Git::Deprecation.warn('The :add_all option for #commit is deprecated, use :all instead') opts[:all] = opts.delete(:add_all) end SharedPrivate.assert_valid_opts!(COMMIT_ALLOWED_OPTS, **opts) call_opts = { no_edit: true } call_opts[:message] = if Git::Commands::Commit.new(@execution_context).call(**call_opts, **opts).stdout end |
#commit_all(message, opts = {}) ⇒ String
Commit all modified tracked files without explicitly staging them first
Equivalent to calling #commit with all: true merged into opts.
107 108 109 |
# File 'lib/git/repository/committing.rb', line 107 def commit_all(, opts = {}) commit(, opts.merge(all: true)) end |
#commit_tree(tree = nil, opts = {}) ⇒ String
Create a commit object from a tree SHA without moving HEAD
Unlike #commit, this does not read the index; it directly wraps
git commit-tree.
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/git/repository/committing.rb', line 142 def commit_tree(tree = nil, opts = {}) # rubocop:disable Metrics/AbcSize SharedPrivate.assert_valid_opts!(COMMIT_TREE_ALLOWED_OPTS, **opts) opts = opts.dup opts[:p] = opts.delete(:parents) if opts.key?(:parents) opts[:p] = opts.delete(:parent) if opts.key?(:parent) opts[:m] = opts.delete(:message) if opts.key?(:message) opts[:m] = "commit tree #{tree}" unless opts[:m] Git::Commands::CommitTree.new(@execution_context).call(tree, **opts).stdout end |
#write_and_commit_tree(opts = {}) ⇒ String
Write the current index to a tree object and immediately commit it
Combines #write_tree and #commit_tree in a single call.
182 183 184 |
# File 'lib/git/repository/committing.rb', line 182 def write_and_commit_tree(opts = {}) commit_tree(write_tree, opts) end |