Class: Git::Lib Private
- Inherits:
-
Object
- Object
- Git::Lib
- Defined in:
- lib/git/lib.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal git operations
Defined Under Namespace
Classes: HeadState
Constant Summary collapse
- INIT_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:bare], flag: '--bare', type: :boolean }, { keys: [:initial_branch], flag: '--initial-branch', type: :valued_equals } ].freeze
- CLONE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: [:bare], flag: '--bare', type: :boolean }, { keys: [:recursive], flag: '--recursive', type: :boolean }, { keys: [:mirror], flag: '--mirror', type: :boolean }, { keys: [:branch], flag: '--branch', type: :valued_space }, { keys: [:filter], flag: '--filter', type: :valued_space }, { keys: %i[remote origin], flag: '--origin', type: :valued_space }, { keys: [:config], flag: '--config', type: :repeatable_valued_space }, { keys: [:depth], type: :custom, builder: ->(value) { ['--depth', value.to_i] if value } } ].freeze
- DESCRIBE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The map defining how to translate user options to git command arguments.
{ keys: [:all], flag: '--all', type: :boolean }, { keys: [:tags], flag: '--tags', type: :boolean }, { keys: [:contains], flag: '--contains', type: :boolean }, { keys: [:debug], flag: '--debug', type: :boolean }, { keys: [:long], flag: '--long', type: :boolean }, { keys: [:always], flag: '--always', type: :boolean }, { keys: %i[exact_match exact-match], flag: '--exact-match', type: :boolean }, { keys: [:abbrev], flag: '--abbrev', type: :valued_equals }, { keys: [:candidates], flag: '--candidates', type: :valued_equals }, { keys: [:match], flag: '--match', type: :valued_equals }, { keys: [:dirty], type: :custom, builder: lambda do |value| return '--dirty' if value == true "--dirty=#{value}" if value.is_a?(String) end } ].freeze
- FULL_LOG_EXTRA_OPTIONS_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '--pretty=raw' }, { keys: [:skip], flag: '--skip', type: :valued_equals }, { keys: [:merges], flag: '--merges', type: :boolean } ].freeze
- CAT_FILE_HEADER_LINE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A(?<key>\w+) (?<value>.*)\z/
- LS_TREE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:recursive], flag: '-r', type: :boolean } ].freeze
- BRANCH_LINE_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/ ^ # Prefix indicates if this branch is checked out. The prefix is one of: (?: (?<current>\*[[:blank:]]) | # Current branch (checked out in the current worktree) (?<worktree>\+[[:blank:]]) | # Branch checked out in a different worktree [[:blank:]]{2} # Branch not checked out ) # The branch's full refname (?: (?<not_a_branch>\(not[[:blank:]]a[[:blank:]]branch\)) | (?:\(HEAD[[:blank:]]detached[[:blank:]]at[[:blank:]](?<detached_ref>[^\)]+)\)) | (?<refname>[^[[:blank:]]]+) ) # Optional symref # If this ref is a symbolic reference, this is the ref referenced (?: [[:blank:]]->[[:blank:]](?<symref>.*) )? $ /x
- GREP_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:ignore_case], flag: '-i', type: :boolean }, { keys: [:invert_match], flag: '-v', type: :boolean }, { keys: [:extended_regexp], flag: '-E', type: :boolean }, # For validation only, as these are handled manually { keys: [:object], type: :validate_only }, { keys: [:path_limiter], type: :validate_only } ].freeze
- DIFF_FULL_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '-p' }, { keys: [:path_limiter], type: :validate_only } ].freeze
- DIFF_STATS_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '--numstat' }, { keys: [:path_limiter], type: :validate_only } ].freeze
- DIFF_PATH_STATUS_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '--name-status' }, { keys: [:path], type: :validate_only } ].freeze
- LS_REMOTE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:refs], flag: '--refs', type: :boolean } ].freeze
- CONFIG_SET_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
WRITE COMMANDS ##
[ { keys: [:file], flag: '--file', type: :valued_space } ].freeze
- ADD_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:all], flag: '--all', type: :boolean }, { keys: [:force], flag: '--force', type: :boolean } ].freeze
- RM_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '-f' }, { keys: [:recursive], flag: '-r', type: :boolean }, { keys: [:cached], flag: '--cached', type: :boolean } ].freeze
- COMMIT_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: %i[add_all all], flag: '--all', type: :boolean }, { keys: [:allow_empty], flag: '--allow-empty', type: :boolean }, { keys: [:no_verify], flag: '--no-verify', type: :boolean }, { keys: [:allow_empty_message], flag: '--allow-empty-message', type: :boolean }, { keys: [:author], flag: '--author', type: :valued_equals }, { keys: [:message], flag: '--message', type: :valued_equals }, { keys: [:no_gpg_sign], flag: '--no-gpg-sign', type: :boolean }, { keys: [:date], flag: '--date', type: :valued_equals, validator: ->(v) { v.is_a?(String) } }, { keys: [:amend], type: :custom, builder: ->(value) { ['--amend', '--no-edit'] if value } }, { keys: [:gpg_sign], type: :custom, builder: lambda { |value| if value value == true ? '--gpg-sign' : "--gpg-sign=#{value}" end } } ].freeze
- RESET_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:hard], flag: '--hard', type: :boolean } ].freeze
- CLEAN_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:force], flag: '--force', type: :boolean }, { keys: [:ff], flag: '-ff', type: :boolean }, { keys: [:d], flag: '-d', type: :boolean }, { keys: [:x], flag: '-x', type: :boolean } ].freeze
- REVERT_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:no_edit], flag: '--no-edit', type: :boolean } ].freeze
- CHECKOUT_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: %i[force f], flag: '--force', type: :boolean }, { keys: %i[new_branch b], type: :validate_only }, { keys: [:start_point], type: :validate_only } ].freeze
- MERGE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:no_commit], flag: '--no-commit', type: :boolean }, { keys: [:no_ff], flag: '--no-ff', type: :boolean }, { keys: [:m], flag: '-m', type: :valued_space } ].freeze
- MERGE_BASE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:octopus], flag: '--octopus', type: :boolean }, { keys: [:independent], flag: '--independent', type: :boolean }, { keys: [:fork_point], flag: '--fork-point', type: :boolean }, { keys: [:all], flag: '--all', type: :boolean } ].freeze
- REMOTE_ADD_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: %i[with_fetch fetch], flag: '-f', type: :boolean }, { keys: [:track], flag: '-t', type: :valued_space } ].freeze
- TAG_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: %i[force f], flag: '-f', type: :boolean }, { keys: %i[annotate a], flag: '-a', type: :boolean }, { keys: %i[sign s], flag: '-s', type: :boolean }, { keys: %i[delete d], flag: '-d', type: :boolean }, { keys: %i[message m], flag: '-m', type: :valued_space } ].freeze
- FETCH_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: [:all], flag: '--all', type: :boolean }, { keys: %i[tags t], flag: '--tags', type: :boolean }, { keys: %i[prune p], flag: '--prune', type: :boolean }, { keys: %i[prune-tags P], flag: '--prune-tags', type: :boolean }, { keys: %i[force f], flag: '--force', type: :boolean }, { keys: %i[update-head-ok u], flag: '--update-head-ok', type: :boolean }, { keys: [:unshallow], flag: '--unshallow', type: :boolean }, { keys: [:depth], flag: '--depth', type: :valued_space }, { keys: [:ref], type: :validate_only } ].freeze
- PUSH_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: [:mirror], flag: '--mirror', type: :boolean }, { keys: [:delete], flag: '--delete', type: :boolean }, { keys: %i[force f], flag: '--force', type: :boolean }, { keys: [:push_option], flag: '--push-option', type: :repeatable_valued_space }, { keys: [:all], type: :validate_only }, # For validation purposes { keys: [:tags], type: :validate_only } # From the `push` method's logic ].freeze
- PULL_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:allow_unrelated_histories], flag: '--allow-unrelated-histories', type: :boolean } ].freeze
- READ_TREE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:prefix], flag: '--prefix', type: :valued_equals } ].freeze
- COMMIT_TREE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ keys: %i[parent parents], flag: '-p', type: :repeatable_valued_space }, { keys: [:message], flag: '-m', type: :valued_space } ].freeze
- CHECKOUT_INDEX_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:prefix], flag: '--prefix', type: :valued_equals }, { keys: [:force], flag: '--force', type: :boolean }, { keys: [:all], flag: '--all', type: :boolean }, { keys: [:path_limiter], type: :validate_only } ].freeze
- ARCHIVE_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { keys: [:prefix], flag: '--prefix', type: :valued_equals }, { keys: [:remote], flag: '--remote', type: :valued_equals }, # These options are used by helpers or handled manually { keys: [:path], type: :validate_only }, { keys: [:format], type: :validate_only }, { keys: [:add_gzip], type: :validate_only } ].freeze
- COMMAND_ARG_DEFAULTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ out: nil, err: nil, normalize: true, chomp: true, merge: false, chdir: nil, timeout: nil # Don't set to Git.config.timeout here since it is mutable }.freeze
- STATIC_GLOBAL_OPTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[ -c core.quotePath=true -c color.ui=false -c color.advice=false -c color.diff=false -c color.grep=false -c color.push=false -c color.remote=false -c color.showBranch=false -c color.status=false -c color.transport=false ].freeze
- LOG_OPTION_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ { type: :static, flag: '--no-color' }, { keys: [:all], flag: '--all', type: :boolean }, { keys: [:cherry], flag: '--cherry', type: :boolean }, { keys: [:since], flag: '--since', type: :valued_equals }, { keys: [:until], flag: '--until', type: :valued_equals }, { keys: [:grep], flag: '--grep', type: :valued_equals }, { keys: [:author], flag: '--author', type: :valued_equals }, { keys: [:count], flag: '--max-count', type: :valued_equals }, { keys: [:between], type: :custom, builder: ->(value) { "#{value[0]}..#{value[1]}" if value } } ].freeze
Instance Attribute Summary collapse
-
#git_dir ⇒ Pathname
readonly
private
The path to the Git repository directory.
-
#git_index_file ⇒ Pathname
readonly
private
The Git index file used to stage changes (using
git add
) before they are committed. -
#git_work_dir ⇒ Pathname
readonly
private
The path to the Git working copy.
Class Method Summary collapse
-
.warn_if_old_command(lib)
private
rubocop:disable Naming/PredicateMethod.
Instance Method Summary collapse
-
#add(paths = '.', options = {})
private
Update the index from the current worktree to prepare the for the next commit.
- #apply(patch_file) private
- #apply_mail(patch_file) private
- #archive(sha, file = nil, opts = {}) private
-
#assert_args_are_not_options(arg_name, *args)
private
Validate that the given arguments cannot be mistaken for a command-line option.
- #branch_contains(commit, branch_name = '') private
- #branch_current private
- #branch_delete(branch) private
- #branch_new(branch) private
- #branches_all private
-
#cat_file_commit(object) ⇒ Hash
(also: #commit_data)
private
Return a hash of commit data.
-
#cat_file_contents(object) ⇒ String
(also: #object_contents)
private
Output the contents or other properties of one or more objects.
-
#cat_file_size(object) ⇒ String
(also: #object_size)
private
Get the size for the given object.
-
#cat_file_tag(object) ⇒ Hash
(also: #tag_data)
private
Return a hash of annotated tag data.
-
#cat_file_type(object) ⇒ String
(also: #object_type)
private
Get the type for the given object.
- #change_head_branch(branch_name) private
-
#checkout(branch = nil, opts = {})
private
Runs checkout command to checkout or create branch.
- #checkout_file(version, file) private
- #checkout_index(opts = {}) private
- #clean(opts = {}) private
-
#clone(repository_url, directory, opts = {}) ⇒ Hash
private
Clones a repository into a newly created directory.
-
#commit(message, opts = {})
private
Takes the commit message with the options and executes the commit command.
- #commit_tree(tree, opts = {}) private
-
#compare_version_to(*other_version) ⇒ Integer
private
Returns current_command_version <=> other_version.
- #config_get(name) private
- #config_list private
- #config_remote(name) private
- #config_set(name, value, options = {}) private
-
#conflicts
private
:yields: file, your, their.
-
#current_branch_state ⇒ HeadState
private
The current branch state which is the state of
HEAD
. -
#current_command_version
private
returns the current version of git, as an Array of Fixnums.
-
#describe(commit_ish = nil, opts = {}) ⇒ String
private
Finds most recent tag that is reachable from a commit.
-
#diff_files
private
compares the index and the working directory.
- #diff_full(obj1 = 'HEAD', obj2 = nil, opts = {}) private
-
#diff_index(treeish)
private
compares the index and the repository.
- #diff_path_status(reference1 = nil, reference2 = nil, opts = {}) private
- #diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {}) private
- #each_cat_file_header(data) private
-
#empty? ⇒ Boolean
private
Returns true if the repository is empty (meaning it has no commits).
- #fetch(remote, opts) private
-
#full_log_commits(opts = {}) ⇒ Array<Hash>
private
Return the commits that are within the given revision range.
- #full_tree(sha) private
- #gc private
- #global_config_get(name) private
- #global_config_list private
- #global_config_set(name, value) private
-
#grep(string, opts = {})
private
returns hash [tree-ish] = [[line_no, match], [line_no, match2]] [tree-ish] = [[line_no, match], [line_no, match2]].
- #ignored_files private
-
#init(opts = {})
private
creates or reinitializes the repository.
-
#initialize(base = nil, logger = nil) ⇒ Lib
constructor
private
Create a new Git::Lib object.
- #list_files(ref_dir) private
-
#log_commits(opts = {}) ⇒ Array<String>
private
Return the commits that are within the given revision range.
-
#ls_files(location = nil) ⇒ Hash<String, Hash>
private
List all files that are in the index.
- #ls_remote(location = nil, opts = {}) private
- #ls_tree(sha, opts = {}) private
- #meets_required_version? ⇒ Boolean private
- #merge(branch, message = nil, opts = {}) private
- #merge_base(*args) private
- #mv(file1, file2) private
-
#name_rev(commit_ish) ⇒ String?
(also: #namerev)
private
Find the first symbolic name for given commit_ish.
- #parse_config(file) private
- #parse_config_list(lines) private
- #process_commit_data(data, sha) private
- #process_commit_log_data(data) private
- #process_tag_data(data, name) private
- #pull(remote = nil, branch = nil, opts = {}) private
- #push(remote = nil, branch = nil, opts = nil) private
- #read_tree(treeish, opts = {}) private
- #remote_add(name, url, opts = {}) private
- #remote_remove(name) private
- #remote_set_url(name, url) private
- #remotes private
- #repack private
-
#repository_default_branch(repository) ⇒ String
private
Returns the name of the default branch of the given repository.
- #required_command_version private
- #reset(commit, opts = {}) private
-
#rev_parse(revision) ⇒ String
(also: #revparse)
private
Verify and resolve a Git revision to its full SHA.
- #revert(commitish, opts = {}) private
- #rm(path = '.', opts = {}) private
-
#show(objectish = nil, path = nil) ⇒ String
private
Shows objects.
- #stash_apply(id = nil) private
- #stash_clear private
- #stash_list private
- #stash_save(message) private
- #stashes_all private
- #tag(name, *args) private
- #tag_sha(tag_name) private
- #tags private
- #tree_depth(sha) private
-
#unescape_quoted_path(path) ⇒ String
private
Unescape a path if it is quoted.
- #unmerged private
- #untracked_files private
- #update_ref(ref, commit) private
- #worktree_add(dir, commitish = nil) private
- #worktree_prune private
- #worktree_remove(dir) private
- #worktrees_all private
- #write_tree private
Constructor Details
#initialize(base, logger) ⇒ Lib #initialize(base, logger) ⇒ Lib
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new Git::Lib object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/git/lib.rb', line 65 def initialize(base = nil, logger = nil) @logger = logger || Logger.new(nil) case base when Git::Base initialize_from_base(base) when Hash initialize_from_hash(base) end end |
Instance Attribute Details
#git_dir ⇒ Pathname (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the Git repository directory. The default is
"#{git_work_dir}/.git"
.
34 35 36 |
# File 'lib/git/lib.rb', line 34 def git_dir @git_dir end |
#git_index_file ⇒ Pathname (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The Git index file used to stage changes (using git add
) before they
are committed.
43 44 45 |
# File 'lib/git/lib.rb', line 43 def git_index_file @git_index_file end |
#git_work_dir ⇒ Pathname (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the Git working copy. The default is '"./.git"'.
25 26 27 |
# File 'lib/git/lib.rb', line 25 def git_work_dir @git_work_dir end |
Class Method Details
.warn_if_old_command(lib)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Naming/PredicateMethod
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 |
# File 'lib/git/lib.rb', line 1555 def self.warn_if_old_command(lib) # rubocop:disable Naming/PredicateMethod Git::Deprecation.warn('Git::Lib#warn_if_old_command is deprecated. Use meets_required_version?.') return true if @version_checked @version_checked = true unless lib.meets_required_version? warn "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, " \ "but only found #{lib.current_command_version.join('.')}. You should probably upgrade." end true end |
Instance Method Details
#add(paths = '.', options = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Update the index from the current worktree to prepare the for the next commit
1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/git/lib.rb', line 1048 def add(paths = '.', = {}) args = build_args(, ADD_OPTION_MAP) args << '--' args.concat(Array(paths)) command('add', *args) end |
#apply(patch_file)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1170 1171 1172 1173 1174 |
# File 'lib/git/lib.rb', line 1170 def apply(patch_file) arr_opts = [] arr_opts << '--' << patch_file if patch_file command('apply', *arr_opts) end |
#apply_mail(patch_file)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1176 1177 1178 1179 1180 |
# File 'lib/git/lib.rb', line 1176 def apply_mail(patch_file) arr_opts = [] arr_opts << '--' << patch_file if patch_file command('am', *arr_opts) end |
#archive(sha, file = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 |
# File 'lib/git/lib.rb', line 1507 def archive(sha, file = nil, opts = {}) ArgsBuilder.validate!(opts, ARCHIVE_OPTION_MAP) file ||= temp_file_name format, gzip = (opts) args = build_args(opts, ARCHIVE_OPTION_MAP) args.unshift("--format=#{format}") args << sha args.push('--', opts[:path]) if opts[:path] File.open(file, 'wb') { |f| command('archive', *args, out: f) } apply_gzip(file) if gzip file end |
#assert_args_are_not_options(arg_name, *args)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validate that the given arguments cannot be mistaken for a command-line option
820 821 822 823 824 825 |
# File 'lib/git/lib.rb', line 820 def (arg_name, *args) invalid_args = args.select { |arg| arg&.start_with?('-') } return unless invalid_args.any? raise ArgumentError, "Invalid #{arg_name}: '#{invalid_args.join("', '")}'" end |
#branch_contains(commit, branch_name = '')
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
781 782 783 |
# File 'lib/git/lib.rb', line 781 def branch_contains(commit, branch_name = '') command('branch', branch_name, '--contains', commit) end |
#branch_current
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
776 777 778 779 |
# File 'lib/git/lib.rb', line 776 def branch_current branch_name = command('branch', '--show-current') branch_name.empty? ? 'HEAD' : branch_name end |
#branch_delete(branch)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1213 1214 1215 |
# File 'lib/git/lib.rb', line 1213 def branch_delete(branch) command('branch', '-D', branch) end |
#branch_new(branch)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1209 1210 1211 |
# File 'lib/git/lib.rb', line 1209 def branch_new(branch) command('branch', branch) end |
#branches_all
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
694 695 696 697 698 699 |
# File 'lib/git/lib.rb', line 694 def branches_all lines = command_lines('branch', '-a') lines.each_with_index.filter_map do |line, index| parse_branch_line(line, index, lines) end end |
#cat_file_commit(object) ⇒ Hash Also known as: commit_data
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a hash of commit data
The returned commit data has the following keys:
- tree [String]
- parent [Array
] - author [String] the author name, email, and commit timestamp
- committer [String] the committer name, email, and merge timestamp
- message [String] the commit message
- gpgsig [String] the public signing key of the commit (if signed)
482 483 484 485 486 487 |
# File 'lib/git/lib.rb', line 482 def cat_file_commit(object) ('object', object) cdata = command_lines('cat-file', 'commit', object) process_commit_data(cdata, object) end |
#cat_file_contents(object) ⇒ String Also known as: object_contents
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Output the contents or other properties of one or more objects.
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/git/lib.rb', line 408 def cat_file_contents(object) ('object', object) if block_given? Tempfile.create do |file| # If a block is given, write the output from the process to a temporary # file and then yield the file to the block # command('cat-file', '-p', object, out: file, err: file) file.rewind yield file end else # If a block is not given, return the file contents as a string command('cat-file', '-p', object) end end |
#cat_file_size(object) ⇒ String Also known as: object_size
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the size for the given object
456 457 458 459 460 |
# File 'lib/git/lib.rb', line 456 def cat_file_size(object) ('object', object) command('cat-file', '-s', object).to_i end |
#cat_file_tag(object) ⇒ Hash Also known as: tag_data
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a hash of annotated tag data
Does not work with lightweight tags. List all annotated tags in your repository with the following command:
git for-each-ref --format='%(refname:strip=2)' refs/tags | \
while read tag; do git cat-file tag $tag >/dev/null 2>&1 && echo $tag; done
The returned commit data has the following keys:
- object [String] the sha of the tag object
- type [String]
- tag [String] tag name
- tagger [String] the name and email of the user who created the tag and the timestamp of when the tag was created
- message [String] the tag message
551 552 553 554 555 556 |
# File 'lib/git/lib.rb', line 551 def cat_file_tag(object) ('object', object) tdata = command_lines('cat-file', 'tag', object) process_tag_data(tdata, object) end |
#cat_file_type(object) ⇒ String Also known as: object_type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the type for the given object
438 439 440 441 442 |
# File 'lib/git/lib.rb', line 438 def cat_file_type(object) ('object', object) command('cat-file', '-t', object) end |
#change_head_branch(branch_name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
666 667 668 |
# File 'lib/git/lib.rb', line 666 def change_head_branch(branch_name) command('symbolic-ref', 'HEAD', "refs/heads/#{branch_name}") end |
#checkout(branch = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs checkout command to checkout or create branch
accepts options: :new_branch :force :start_point
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/git/lib.rb', line 1232 def checkout(branch = nil, opts = {}) if branch.is_a?(Hash) && opts.empty? opts = branch branch = nil end ArgsBuilder.validate!(opts, CHECKOUT_OPTION_MAP) flags = build_args(opts, CHECKOUT_OPTION_MAP) positional_args = build_checkout_positional_args(branch, opts) command('checkout', *flags, *positional_args) end |
#checkout_file(version, file)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1245 1246 1247 1248 1249 1250 |
# File 'lib/git/lib.rb', line 1245 def checkout_file(version, file) arr_opts = [] arr_opts << version arr_opts << file command('checkout', *arr_opts) end |
#checkout_index(opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 |
# File 'lib/git/lib.rb', line 1487 def checkout_index(opts = {}) ArgsBuilder.validate!(opts, CHECKOUT_INDEX_OPTION_MAP) args = build_args(opts, CHECKOUT_INDEX_OPTION_MAP) if (path = opts[:path_limiter]) && path.is_a?(String) args.push('--', path) end command('checkout-index', *args) end |
#clean(opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1151 1152 1153 1154 |
# File 'lib/git/lib.rb', line 1151 def clean(opts = {}) args = build_args(opts, CLEAN_OPTION_MAP) command('clean', *args) end |
#clone(repository_url, directory, opts = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
make this work with SSH password or auth_key
Clones a repository into a newly created directory
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/git/lib.rb', line 149 def clone(repository_url, directory, opts = {}) @path = opts[:path] || '.' clone_dir = opts[:path] ? File.join(@path, directory) : directory args = build_args(opts, CLONE_OPTION_MAP) args.push('--', repository_url, clone_dir) command('clone', *args, timeout: opts[:timeout]) return_base_opts_from_clone(clone_dir, opts) end |
#commit(message, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Takes the commit message with the options and executes the commit command
accepts options: :amend :all :allow_empty :author :date :no_verify :allow_empty_message :gpg_sign (accepts true or a gpg key ID as a String) :no_gpg_sign (conflicts with :gpg_sign)
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
# File 'lib/git/lib.rb', line 1123 def commit(, opts = {}) opts[:message] = if # Handle message arg for backward compatibility # Perform cross-option validation before building args raise ArgumentError, 'cannot specify :gpg_sign and :no_gpg_sign' if opts[:gpg_sign] && opts[:no_gpg_sign] ArgsBuilder.validate!(opts, COMMIT_OPTION_MAP) args = build_args(opts, COMMIT_OPTION_MAP) command('commit', *args) end |
#commit_tree(tree, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1468 1469 1470 1471 1472 1473 1474 |
# File 'lib/git/lib.rb', line 1468 def commit_tree(tree, opts = {}) opts[:message] ||= "commit tree #{tree}" ArgsBuilder.validate!(opts, COMMIT_TREE_OPTION_MAP) flags = build_args(opts, COMMIT_TREE_OPTION_MAP) command('commit-tree', tree, *flags) end |
#compare_version_to(*other_version) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns current_command_version <=> other_version
1543 1544 1545 |
# File 'lib/git/lib.rb', line 1543 def compare_version_to(*other_version) current_command_version <=> other_version end |
#config_get(name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
972 973 974 |
# File 'lib/git/lib.rb', line 972 def config_get(name) command('config', '--get', name, chdir: @git_dir) end |
#config_list
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
980 981 982 |
# File 'lib/git/lib.rb', line 980 def config_list parse_config_list command_lines('config', '--list', chdir: @git_dir) end |
#config_remote(name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
964 965 966 967 968 969 970 |
# File 'lib/git/lib.rb', line 964 def config_remote(name) hsh = {} config_list.each do |key, value| hsh[key.gsub("remote.#{name}.", '')] = value if /remote.#{name}/.match(key) end hsh end |
#config_set(name, value, options = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1020 1021 1022 1023 1024 |
# File 'lib/git/lib.rb', line 1020 def config_set(name, value, = {}) ArgsBuilder.validate!(, CONFIG_SET_OPTION_MAP) flags = build_args(, CONFIG_SET_OPTION_MAP) command('config', *flags, name, value) end |
#conflicts
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:yields: file, your, their
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 |
# File 'lib/git/lib.rb', line 1294 def conflicts # :yields: file, your, their unmerged.each do |file_path| Tempfile.create(['YOUR-', File.basename(file_path)]) do |your_file| write_staged_content(file_path, 2, your_file).flush Tempfile.create(['THEIR-', File.basename(file_path)]) do |their_file| write_staged_content(file_path, 3, their_file).flush yield(file_path, your_file.path, their_file.path) end end end end |
#current_branch_state ⇒ HeadState
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current branch state which is the state of HEAD
768 769 770 771 772 773 774 |
# File 'lib/git/lib.rb', line 768 def current_branch_state branch_name = command('branch', '--show-current') return HeadState.new(:detached, 'HEAD') if branch_name.empty? state = get_branch_state(branch_name) HeadState.new(state, branch_name) end |
#current_command_version
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
returns the current version of git, as an Array of Fixnums.
1524 1525 1526 1527 1528 1529 |
# File 'lib/git/lib.rb', line 1524 def current_command_version output = command('version') version = output[/\d+(\.\d+)+/] version_parts = version.split('.').collect(&:to_i) version_parts.fill(0, version_parts.length...3) end |
#describe(commit_ish = nil, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds most recent tag that is reachable from a commit
228 229 230 231 232 233 234 235 |
# File 'lib/git/lib.rb', line 228 def describe(commit_ish = nil, opts = {}) ('commit-ish object', commit_ish) args = build_args(opts, DESCRIBE_OPTION_MAP) args << commit_ish if commit_ish command('describe', *args) end |
#diff_files
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
compares the index and the working directory
883 884 885 |
# File 'lib/git/lib.rb', line 883 def diff_files diff_as_hash('diff-files') end |
#diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
832 833 834 835 836 837 838 839 840 841 842 843 844 |
# File 'lib/git/lib.rb', line 832 def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {}) ('commit or commit range', obj1, obj2) ArgsBuilder.validate!(opts, DIFF_FULL_OPTION_MAP) args = build_args(opts, DIFF_FULL_OPTION_MAP) args.push(obj1, obj2).compact! if (path = opts[:path_limiter]) && path.is_a?(String) args.push('--', path) end command('diff', *args) end |
#diff_index(treeish)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
compares the index and the repository
888 889 890 |
# File 'lib/git/lib.rb', line 888 def diff_index(treeish) diff_as_hash('diff-index', treeish) end |
#diff_path_status(reference1 = nil, reference2 = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
871 872 873 874 875 876 877 878 879 880 |
# File 'lib/git/lib.rb', line 871 def diff_path_status(reference1 = nil, reference2 = nil, opts = {}) ('commit or commit range', reference1, reference2) ArgsBuilder.validate!(opts, DIFF_PATH_STATUS_OPTION_MAP) args = build_args(opts, DIFF_PATH_STATUS_OPTION_MAP) args.push(reference1, reference2).compact! args.push('--', opts[:path]) if opts[:path] parse_diff_path_status(args) end |
#diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'lib/git/lib.rb', line 851 def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {}) ('commit or commit range', obj1, obj2) ArgsBuilder.validate!(opts, DIFF_STATS_OPTION_MAP) args = build_args(opts, DIFF_STATS_OPTION_MAP) args.push(obj1, obj2).compact! if (path = opts[:path_limiter]) && path.is_a?(String) args.push('--', path) end output_lines = command_lines('diff', *args) parse_diff_stats_output(output_lines) end |
#each_cat_file_header(data)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
502 503 504 505 506 507 508 509 510 511 |
# File 'lib/git/lib.rb', line 502 def each_cat_file_header(data) while (match = CAT_FILE_HEADER_LINE.match(data.shift)) key = match[:key] value_lines = [match[:value]] value_lines << data.shift.lstrip while data.first.start_with?(' ') yield key, value_lines.join("\n") end end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the repository is empty (meaning it has no commits)
1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/git/lib.rb', line 1076 def empty? command('rev-parse', '--verify', 'HEAD') false rescue Git::FailedError => e raise unless e.result.status.exitstatus == 128 && e.result.stderr == 'fatal: Needed a single revision' true end |
#fetch(remote, opts)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 |
# File 'lib/git/lib.rb', line 1375 def fetch(remote, opts) ArgsBuilder.validate!(opts, FETCH_OPTION_MAP) args = build_args(opts, FETCH_OPTION_MAP) if remote || opts[:ref] args << '--' args << remote if remote args << opts[:ref] if opts[:ref] end command('fetch', *args, merge: true) end |
#full_log_commits(opts = {}) ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the commits that are within the given revision range
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/git/lib.rb', line 337 def full_log_commits(opts = {}) ('between', opts[:between]&.first) ('object', opts[:object]) args = (opts) args += build_args(opts, FULL_LOG_EXTRA_OPTIONS_MAP) args += (opts) full_log = command_lines('log', *args) process_commit_log_data(full_log) end |
#full_tree(sha)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
658 659 660 |
# File 'lib/git/lib.rb', line 658 def full_tree(sha) command_lines('ls-tree', '-r', sha) end |
#gc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1445 1446 1447 |
# File 'lib/git/lib.rb', line 1445 def gc command('gc', '--prune', '--aggressive', '--auto') end |
#global_config_get(name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
976 977 978 |
# File 'lib/git/lib.rb', line 976 def global_config_get(name) command('config', '--global', '--get', name) end |
#global_config_list
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
984 985 986 |
# File 'lib/git/lib.rb', line 984 def global_config_list parse_config_list command_lines('config', '--global', '--list') end |
#global_config_set(name, value)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1026 1027 1028 |
# File 'lib/git/lib.rb', line 1026 def global_config_set(name, value) command('config', '--global', name, value) end |
#grep(string, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
returns hash [tree-ish] = [[line_no, match], [line_no, match2]] [tree-ish] = [[line_no, match], [line_no, match2]]
797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/git/lib.rb', line 797 def grep(string, opts = {}) opts[:object] ||= 'HEAD' ArgsBuilder.validate!(opts, GREP_OPTION_MAP) boolean_flags = build_args(opts, GREP_OPTION_MAP) args = ['-n', *boolean_flags, '-e', string, opts[:object]] if (limiter = opts[:path_limiter]) args.push('--', *Array(limiter)) end lines = execute_grep_command(args) parse_grep_output(lines) end |
#ignored_files
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
954 955 956 |
# File 'lib/git/lib.rb', line 954 def ignored_files command_lines('ls-files', '--others', '-i', '--exclude-standard').map { |f| unescape_quoted_path(f) } end |
#init(opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
creates or reinitializes the repository
options: :bare :working_directory :initial_branch
88 89 90 91 |
# File 'lib/git/lib.rb', line 88 def init(opts = {}) args = build_args(opts, INIT_OPTION_MAP) command('init', *args) end |
#list_files(ref_dir)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
735 736 737 738 |
# File 'lib/git/lib.rb', line 735 def list_files(ref_dir) dir = File.join(@git_dir, 'refs', ref_dir) Dir.glob('**/*', base: dir).select { |f| File.file?(File.join(dir, f)) } end |
#log_commits(opts = {}) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the commits that are within the given revision range
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/git/lib.rb', line 264 def log_commits(opts = {}) ('between', opts[:between]&.first) ('object', opts[:object]) arr_opts = (opts) arr_opts << '--pretty=oneline' arr_opts += (opts) command_lines('log', *arr_opts).map { |l| l.split.first } end |
#ls_files(location = nil) ⇒ Hash<String, Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List all files that are in the index
904 905 906 907 908 909 910 911 912 913 914 915 |
# File 'lib/git/lib.rb', line 904 def ls_files(location = nil) location ||= '.' {}.tap do |files| command_lines('ls-files', '--stage', location).each do |line| (info, file) = split_status_line(line) (mode, sha, stage) = info.split files[file] = { path: file, mode_index: mode, sha_index: sha, stage: stage } end end end |
#ls_remote(location = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
944 945 946 947 948 949 950 951 952 |
# File 'lib/git/lib.rb', line 944 def ls_remote(location = nil, opts = {}) ArgsBuilder.validate!(opts, LS_REMOTE_OPTION_MAP) flags = build_args(opts, LS_REMOTE_OPTION_MAP) positional_arg = location || '.' output_lines = command_lines('ls-remote', *flags, positional_arg) parse_ls_remote_output(output_lines) end |
#ls_tree(sha, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/git/lib.rb', line 638 def ls_tree(sha, opts = {}) data = { 'blob' => {}, 'tree' => {}, 'commit' => {} } args = build_args(opts, LS_TREE_OPTION_MAP) args.unshift(sha) args << opts[:path] if opts[:path] command_lines('ls-tree', *args).each do |line| (info, filenm) = split_status_line(line) (mode, type, sha) = info.split data[type][filenm] = { mode: mode, sha: sha } end data end |
#meets_required_version? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1551 1552 1553 |
# File 'lib/git/lib.rb', line 1551 def meets_required_version? (current_command_version <=> required_command_version) >= 0 end |
#merge(branch, message = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/git/lib.rb', line 1258 def merge(branch, = nil, opts = {}) # For backward compatibility, treat the message arg as the :m option. opts[:m] = if ArgsBuilder.validate!(opts, MERGE_OPTION_MAP) args = build_args(opts, MERGE_OPTION_MAP) args.concat(Array(branch)) command('merge', *args) end |
#merge_base(*args)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/git/lib.rb', line 1276 def merge_base(*args) opts = args.last.is_a?(Hash) ? args.pop : {} ArgsBuilder.validate!(opts, MERGE_BASE_OPTION_MAP) flags = build_args(opts, MERGE_BASE_OPTION_MAP) command_args = flags + args command('merge-base', *command_args).lines.map(&:strip) end |
#mv(file1, file2)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
654 655 656 |
# File 'lib/git/lib.rb', line 654 def mv(file1, file2) command_lines('mv', '--', file1, file2) end |
#name_rev(commit_ish) ⇒ String? Also known as: namerev
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find the first symbolic name for given commit_ish
384 385 386 387 388 |
# File 'lib/git/lib.rb', line 384 def name_rev(commit_ish) ('commit_ish', commit_ish) command('name-rev', commit_ish).split[1] end |
#parse_config(file)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
997 998 999 |
# File 'lib/git/lib.rb', line 997 def parse_config(file) parse_config_list command_lines('config', '--list', '--file', file) end |
#parse_config_list(lines)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
988 989 990 991 992 993 994 995 |
# File 'lib/git/lib.rb', line 988 def parse_config_list(lines) hsh = {} lines.each do |line| (key, *values) = line.split('=') hsh[key] = values.join('=') end hsh end |
#process_commit_data(data, sha)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
491 492 493 494 495 496 497 498 |
# File 'lib/git/lib.rb', line 491 def process_commit_data(data, sha) # process_commit_headers consumes the header lines from the `data` array, # leaving only the message lines behind. headers = process_commit_headers(data) = "#{data.join("\n")}\n" { 'sha' => sha, 'message' => }.merge(headers) end |
#process_commit_log_data(data)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
572 573 574 |
# File 'lib/git/lib.rb', line 572 def process_commit_log_data(data) RawLogParser.new(data).parse end |
#process_tag_data(data, name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/git/lib.rb', line 560 def process_tag_data(data, name) hsh = { 'name' => name } each_cat_file_header(data) do |key, value| hsh[key] = value end hsh['message'] = "#{data.join("\n")}\n" hsh end |
#pull(remote = nil, branch = nil, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 |
# File 'lib/git/lib.rb', line 1417 def pull(remote = nil, branch = nil, opts = {}) raise ArgumentError, 'You must specify a remote if a branch is specified' if remote.nil? && !branch.nil? ArgsBuilder.validate!(opts, PULL_OPTION_MAP) flags = build_args(opts, PULL_OPTION_MAP) positional_args = [remote, branch].compact command('pull', *flags, *positional_args) end |
#push(remote = nil, branch = nil, opts = nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 |
# File 'lib/git/lib.rb', line 1397 def push(remote = nil, branch = nil, opts = nil) remote, branch, opts = normalize_push_args(remote, branch, opts) ArgsBuilder.validate!(opts, PUSH_OPTION_MAP) raise ArgumentError, 'remote is required if branch is specified' if !remote && branch args = build_push_args(remote, branch, opts) if opts[:mirror] command('push', *args) else command('push', *args) command('push', '--tags', *(args - [branch].compact)) if opts[:tags] end end |
#read_tree(treeish, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1453 1454 1455 1456 1457 |
# File 'lib/git/lib.rb', line 1453 def read_tree(treeish, opts = {}) ArgsBuilder.validate!(opts, READ_TREE_OPTION_MAP) flags = build_args(opts, READ_TREE_OPTION_MAP) command('read-tree', *flags, treeish) end |
#remote_add(name, url, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1312 1313 1314 1315 1316 1317 1318 1319 1320 |
# File 'lib/git/lib.rb', line 1312 def remote_add(name, url, opts = {}) ArgsBuilder.validate!(opts, REMOTE_ADD_OPTION_MAP) flags = build_args(opts, REMOTE_ADD_OPTION_MAP) positional_args = ['--', name, url] command_args = ['add'] + flags + positional_args command('remote', *command_args) end |
#remote_remove(name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1330 1331 1332 |
# File 'lib/git/lib.rb', line 1330 def remote_remove(name) command('remote', 'rm', name) end |
#remote_set_url(name, url)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1322 1323 1324 1325 1326 1327 1328 |
# File 'lib/git/lib.rb', line 1322 def remote_set_url(name, url) arr_opts = ['set-url'] arr_opts << name arr_opts << url command('remote', *arr_opts) end |
#remotes
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1334 1335 1336 |
# File 'lib/git/lib.rb', line 1334 def remotes command_lines('remote') end |
#repack
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1441 1442 1443 |
# File 'lib/git/lib.rb', line 1441 def repack command('repack', '-a', '-d') end |
#repository_default_branch(repository) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the name of the default branch of the given repository
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/lib.rb', line 167 def repository_default_branch(repository) output = command('ls-remote', '--symref', '--', repository, 'HEAD') match_data = output.match(%r{^ref: refs/remotes/origin/(?<default_branch>[^\t]+)\trefs/remotes/origin/HEAD$}) return match_data[:default_branch] if match_data match_data = output.match(%r{^ref: refs/heads/(?<default_branch>[^\t]+)\tHEAD$}) return match_data[:default_branch] if match_data raise Git::UnexpectedResultError, 'Unable to determine the default branch' end |
#required_command_version
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1547 1548 1549 |
# File 'lib/git/lib.rb', line 1547 def required_command_version [2, 28] end |
#reset(commit, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1138 1139 1140 1141 1142 |
# File 'lib/git/lib.rb', line 1138 def reset(commit, opts = {}) args = build_args(opts, RESET_OPTION_MAP) args << commit if commit command('reset', *args) end |
#rev_parse(revision) ⇒ String Also known as: revparse
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Verify and resolve a Git revision to its full SHA
367 368 369 370 371 |
# File 'lib/git/lib.rb', line 367 def rev_parse(revision) ('rev', revision) command('rev-parse', '--revs-only', '--end-of-options', revision, '--') end |
#revert(commitish, opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/git/lib.rb', line 1160 def revert(commitish, opts = {}) # Forcing --no-edit as default since it's not an interactive session. opts = { no_edit: true }.merge(opts) args = build_args(opts, REVERT_OPTION_MAP) args << commitish command('revert', *args) end |
#rm(path = '.', opts = {})
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/git/lib.rb', line 1063 def rm(path = '.', opts = {}) args = build_args(opts, RM_OPTION_MAP) args << '--' args.concat(Array(path)) command('rm', *args) end |
#show(objectish = nil, path = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Shows objects
1006 1007 1008 1009 1010 1011 1012 |
# File 'lib/git/lib.rb', line 1006 def show(objectish = nil, path = nil) arr_opts = [] arr_opts << (path ? "#{objectish}:#{path}" : objectish) command('show', *arr_opts.compact, chomp: false) end |
#stash_apply(id = nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/git/lib.rb', line 1193 def stash_apply(id = nil) if id command('stash', 'apply', id) else command('stash', 'apply') end end |
#stash_clear
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1201 1202 1203 |
# File 'lib/git/lib.rb', line 1201 def stash_clear command('stash', 'clear') end |
#stash_list
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1205 1206 1207 |
# File 'lib/git/lib.rb', line 1205 def stash_list command('stash', 'list') end |
#stash_save(message)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1188 1189 1190 1191 |
# File 'lib/git/lib.rb', line 1188 def stash_save() output = command('stash', 'save', ) output =~ /HEAD is now at/ end |
#stashes_all
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1182 1183 1184 1185 1186 |
# File 'lib/git/lib.rb', line 1182 def stashes_all stash_log_lines.each_with_index.map do |line, index| parse_stash_log_line(line, index) end end |
#tag(name, *args)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 |
# File 'lib/git/lib.rb', line 1350 def tag(name, *args) opts = args.last.is_a?(Hash) ? args.pop : {} target = args.first (opts) ArgsBuilder.validate!(opts, TAG_OPTION_MAP) flags = build_args(opts, TAG_OPTION_MAP) positional_args = [name, target].compact command('tag', *flags, *positional_args) end |
#tag_sha(tag_name)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/git/lib.rb', line 1428 def tag_sha(tag_name) head = File.join(@git_dir, 'refs', 'tags', tag_name) return File.read(head).chomp if File.exist?(head) begin command('show-ref', '--tags', '-s', tag_name) rescue Git::FailedError => e raise unless e.result.status.exitstatus == 1 && e.result.stderr == '' '' end end |
#tags
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1338 1339 1340 |
# File 'lib/git/lib.rb', line 1338 def command_lines('tag') end |
#tree_depth(sha)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
662 663 664 |
# File 'lib/git/lib.rb', line 662 def tree_depth(sha) full_tree(sha).size end |
#unescape_quoted_path(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Unescape a path if it is quoted
Git commands that output paths (e.g. ls-files, diff), will escape unusual characters.
932 933 934 935 936 937 938 |
# File 'lib/git/lib.rb', line 932 def unescape_quoted_path(path) if path.start_with?('"') && path.end_with?('"') Git::EscapedPath.new(path[1..-2]).unescape else path end end |
#unmerged
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1286 1287 1288 1289 1290 1291 1292 |
# File 'lib/git/lib.rb', line 1286 def unmerged unmerged = [] command_lines('diff', '--cached').each do |line| unmerged << ::Regexp.last_match(1) if line =~ /^\* Unmerged path (.*)/ end unmerged end |
#untracked_files
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
958 959 960 961 962 |
# File 'lib/git/lib.rb', line 958 def untracked_files command_lines('ls-files', '--others', '--exclude-standard', chdir: @git_work_dir).map do |f| unescape_quoted_path(f) end end |
#update_ref(ref, commit)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1476 1477 1478 |
# File 'lib/git/lib.rb', line 1476 def update_ref(ref, commit) command('update-ref', ref, commit) end |
#worktree_add(dir, commitish = nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
721 722 723 724 725 |
# File 'lib/git/lib.rb', line 721 def worktree_add(dir, commitish = nil) return command('worktree', 'add', dir, commitish) unless commitish.nil? command('worktree', 'add', dir) end |
#worktree_prune
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
731 732 733 |
# File 'lib/git/lib.rb', line 731 def worktree_prune command('worktree', 'prune') end |
#worktree_remove(dir)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
727 728 729 |
# File 'lib/git/lib.rb', line 727 def worktree_remove(dir) command('worktree', 'remove', dir) end |
#worktrees_all
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'lib/git/lib.rb', line 701 def worktrees_all arr = [] directory = '' # Output example for `worktree list --porcelain`: # worktree /code/public/ruby-git # HEAD 4bef5abbba073c77b4d0ccc1ffcd0ed7d48be5d4 # branch refs/heads/master # # worktree /tmp/worktree-1 # HEAD b8c63206f8d10f57892060375a86ae911fad356e # detached # command_lines('worktree', 'list', '--porcelain').each do |w| s = w.split directory = s[1] if s[0] == 'worktree' arr << [directory, s[1]] if s[0] == 'HEAD' end arr end |
#write_tree
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
1459 1460 1461 |
# File 'lib/git/lib.rb', line 1459 def write_tree command('write-tree') end |