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 = nil, **options) ⇒ String
Record staged changes as a new commit.
-
#commit_all(message, **options) ⇒ String
Commit all modified tracked files without explicitly staging them first.
-
#commit_tree(tree, **options) ⇒ String
Create a commit object from a tree SHA without moving HEAD.
-
#write_and_commit_tree(**options) ⇒ 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 = nil, **options) ⇒ String
Record staged changes as a new commit
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/git/repository/committing.rb', line 77 def commit( = nil, **opts) 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, **options) ⇒ String
Commit all modified tracked files without explicitly staging them first
Equivalent to commit(message, all: true, **options).
110 111 112 |
# File 'lib/git/repository/committing.rb', line 110 def commit_all(*, **) commit(*, all: true, **) end |
#commit_tree(tree, **options) ⇒ 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.
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/git/repository/committing.rb', line 147 def commit_tree(tree, **opts) SharedPrivate.assert_valid_opts!(COMMIT_TREE_ALLOWED_OPTS, **opts) 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(**options) ⇒ String
Write the current index to a tree object and immediately commit it
Combines #write_tree and #commit_tree in a single call.
186 187 188 |
# File 'lib/git/repository/committing.rb', line 186 def write_and_commit_tree(**) commit_tree(write_tree, **) end |