Module: Git
- Defined in:
- lib/git.rb,
lib/git.rb,
lib/git/lib.rb,
lib/git/log.rb,
lib/git/url.rb,
lib/git/base.rb,
lib/git/diff.rb,
lib/git/stash.rb,
lib/git/author.rb,
lib/git/branch.rb,
lib/git/config.rb,
lib/git/errors.rb,
lib/git/object.rb,
lib/git/remote.rb,
lib/git/status.rb,
lib/git/status.rb,
lib/git/status.rb,
lib/git/stashes.rb,
lib/git/version.rb,
lib/git/branches.rb,
lib/git/commands.rb,
lib/git/file_ref.rb,
lib/git/tag_info.rb,
lib/git/worktree.rb,
lib/git/diff_info.rb,
lib/git/worktrees.rb,
lib/git/diff_stats.rb,
lib/git/repository.rb,
lib/git/stash_info.rb,
lib/git/branch_info.rb,
lib/git/commands/am.rb,
lib/git/commands/gc.rb,
lib/git/commands/mv.rb,
lib/git/commands/rm.rb,
lib/git/diff_result.rb,
lib/git/fsck_object.rb,
lib/git/fsck_result.rb,
lib/git/parsers/tag.rb,
lib/git/args_builder.rb,
lib/git/command_line.rb,
lib/git/commands/add.rb,
lib/git/commands/log.rb,
lib/git/commands/tag.rb,
lib/git/dirstat_info.rb,
lib/git/escaped_path.rb,
lib/git/parsers/diff.rb,
lib/git/parsers/fsck.rb,
lib/git/parsers/grep.rb,
lib/git/commands/base.rb,
lib/git/commands/diff.rb,
lib/git/commands/fsck.rb,
lib/git/commands/grep.rb,
lib/git/commands/init.rb,
lib/git/commands/pull.rb,
lib/git/commands/push.rb,
lib/git/commands/show.rb,
lib/git/parsers/stash.rb,
lib/git/commands/apply.rb,
lib/git/commands/clean.rb,
lib/git/commands/clone.rb,
lib/git/commands/fetch.rb,
lib/git/commands/merge.rb,
lib/git/commands/reset.rb,
lib/git/commands/stash.rb,
lib/git/encoding_utils.rb,
lib/git/parsers/branch.rb,
lib/git/commands/branch.rb,
lib/git/commands/commit.rb,
lib/git/commands/remote.rb,
lib/git/commands/repack.rb,
lib/git/commands/revert.rb,
lib/git/commands/status.rb,
lib/git/parsers/ls_tree.rb,
lib/git/commands/am/quit.rb,
lib/git/commands/am/skip.rb,
lib/git/commands/archive.rb,
lib/git/commands/ls_tree.rb,
lib/git/commands/version.rb,
lib/git/diff_path_status.rb,
lib/git/parsers/cat_file.rb,
lib/git/command_line/base.rb,
lib/git/commands/am/abort.rb,
lib/git/commands/am/apply.rb,
lib/git/commands/am/retry.rb,
lib/git/commands/cat_file.rb,
lib/git/commands/checkout.rb,
lib/git/commands/describe.rb,
lib/git/commands/ls_files.rb,
lib/git/commands/name_rev.rb,
lib/git/commands/show_ref.rb,
lib/git/commands/tag/list.rb,
lib/git/commands/worktree.rb,
lib/git/execution_context.rb,
lib/git/tag_delete_result.rb,
lib/git/commands/arguments.rb,
lib/git/commands/ls_remote.rb,
lib/git/commands/read_tree.rb,
lib/git/commands/rev_parse.rb,
lib/git/commands/stash/pop.rb,
lib/git/detached_head_info.rb,
lib/git/diff_file_raw_info.rb,
lib/git/repository/diffing.rb,
lib/git/repository/logging.rb,
lib/git/repository/merging.rb,
lib/git/repository/staging.rb,
lib/git/tag_delete_failure.rb,
lib/git/version_constraint.rb,
lib/git/command_line/result.rb,
lib/git/command_line_result.rb,
lib/git/commands/diff_files.rb,
lib/git/commands/diff_index.rb,
lib/git/commands/merge/quit.rb,
lib/git/commands/merge_base.rb,
lib/git/commands/remote/add.rb,
lib/git/commands/stash/drop.rb,
lib/git/commands/stash/list.rb,
lib/git/commands/stash/push.rb,
lib/git/commands/stash/show.rb,
lib/git/commands/tag/create.rb,
lib/git/commands/tag/delete.rb,
lib/git/commands/tag/verify.rb,
lib/git/commands/update_ref.rb,
lib/git/commands/write_tree.rb,
lib/git/repository/stashing.rb,
lib/git/branch_delete_result.rb,
lib/git/commands/am/continue.rb,
lib/git/commands/branch/copy.rb,
lib/git/commands/branch/list.rb,
lib/git/commands/branch/move.rb,
lib/git/commands/commit_tree.rb,
lib/git/commands/maintenance.rb,
lib/git/commands/merge/abort.rb,
lib/git/commands/merge/start.rb,
lib/git/commands/remote/list.rb,
lib/git/commands/remote/show.rb,
lib/git/commands/revert/quit.rb,
lib/git/commands/revert/skip.rb,
lib/git/commands/stash/apply.rb,
lib/git/commands/stash/clear.rb,
lib/git/commands/stash/store.rb,
lib/git/diff_file_patch_info.rb,
lib/git/repository/branching.rb,
lib/git/branch_delete_failure.rb,
lib/git/commands/cat_file/raw.rb,
lib/git/commands/remote/prune.rb,
lib/git/commands/revert/abort.rb,
lib/git/commands/revert/start.rb,
lib/git/commands/stash/branch.rb,
lib/git/commands/stash/create.rb,
lib/git/commands/symbolic_ref.rb,
lib/git/commands/worktree/add.rb,
lib/git/repository/committing.rb,
lib/git/repository/inspecting.rb,
lib/git/command_line/capturing.rb,
lib/git/command_line/streaming.rb,
lib/git/commands/branch/create.rb,
lib/git/commands/branch/delete.rb,
lib/git/commands/remote/remove.rb,
lib/git/commands/remote/rename.rb,
lib/git/commands/remote/update.rb,
lib/git/commands/show_ref/list.rb,
lib/git/commands/worktree/list.rb,
lib/git/commands/worktree/lock.rb,
lib/git/commands/worktree/move.rb,
lib/git/diff_file_numstat_info.rb,
lib/git/repository/configuring.rb,
lib/git/commands/cat_file/batch.rb,
lib/git/commands/checkout/files.rb,
lib/git/commands/checkout_index.rb,
lib/git/commands/merge/continue.rb,
lib/git/commands/remote/get_url.rb,
lib/git/commands/remote/set_url.rb,
lib/git/commands/worktree/prune.rb,
lib/git/commands/checkout/branch.rb,
lib/git/commands/maintenance/run.rb,
lib/git/commands/remote/set_head.rb,
lib/git/commands/revert/continue.rb,
lib/git/commands/show_ref/exists.rb,
lib/git/commands/show_ref/verify.rb,
lib/git/commands/worktree/remove.rb,
lib/git/commands/worktree/repair.rb,
lib/git/commands/worktree/unlock.rb,
lib/git/execution_context/global.rb,
lib/git/repository/path_resolver.rb,
lib/git/commands/maintenance/stop.rb,
lib/git/commands/update_ref/batch.rb,
lib/git/repository/shared_private.rb,
lib/git/commands/cat_file/filtered.rb,
lib/git/commands/maintenance/start.rb,
lib/git/commands/symbolic_ref/read.rb,
lib/git/commands/update_ref/delete.rb,
lib/git/commands/update_ref/update.rb,
lib/git/commands/remote/set_url_add.rb,
lib/git/commands/branch/set_upstream.rb,
lib/git/commands/branch/show_current.rb,
lib/git/commands/remote/set_branches.rb,
lib/git/commands/symbolic_ref/delete.rb,
lib/git/commands/symbolic_ref/update.rb,
lib/git/execution_context/repository.rb,
lib/git/repository/object_operations.rb,
lib/git/repository/remote_operations.rb,
lib/git/repository/status_operations.rb,
lib/git/commands/archive/list_formats.rb,
lib/git/commands/config_option_syntax.rb,
lib/git/commands/maintenance/register.rb,
lib/git/commands/am/show_current_patch.rb,
lib/git/commands/branch/unset_upstream.rb,
lib/git/commands/remote/set_url_delete.rb,
lib/git/repository/worktree_operations.rb,
lib/git/commands/maintenance/unregister.rb,
lib/git/commands/config_option_syntax/add.rb,
lib/git/commands/config_option_syntax/get.rb,
lib/git/commands/config_option_syntax/set.rb,
lib/git/commands/worktree/management_base.rb,
lib/git/commands/config_option_syntax/list.rb,
lib/git/commands/show_ref/exclude_existing.rb,
lib/git/commands/config_option_syntax/unset.rb,
lib/git/commands/config_option_syntax/get_all.rb,
lib/git/commands/config_option_syntax/get_color.rb,
lib/git/commands/config_option_syntax/unset_all.rb,
lib/git/commands/config_option_syntax/get_regexp.rb,
lib/git/commands/config_option_syntax/replace_all.rb,
lib/git/commands/config_option_syntax/get_urlmatch.rb,
lib/git/commands/config_option_syntax/get_color_bool.rb,
lib/git/commands/config_option_syntax/remove_section.rb,
lib/git/commands/config_option_syntax/rename_section.rb
Overview
These would be required by the main git.rb file
Defined Under Namespace
Modules: CommandLine, Commands, EncodingUtils, Parsers Classes: ArgsBuilder, Author, Base, Branch, BranchDeleteFailure, BranchDeleteResult, BranchInfo, Branches, CommandLineError, Config, DetachedHeadInfo, Diff, DiffFileNumstatInfo, DiffFilePatchInfo, DiffFileRawInfo, DiffInfo, DiffPathStatus, DiffResult, DiffStats, DirstatEntry, DirstatInfo, Error, EscapedPath, ExecutionContext, FailedError, FileDiffInfo, FileRef, FsckObject, FsckResult, GitAltURI, Lib, Log, Object, ProcessIOError, Remote, Repository, SignaledError, Stash, StashInfo, Stashes, Status, TagDeleteFailure, TagDeleteResult, TagInfo, TimeoutError, URL, UnexpectedResultError, Version, VersionConstraint, VersionError, Worktree, Worktrees
Constant Summary collapse
- Deprecation =
ActiveSupport::Deprecation.new('5.0.0', 'Git')
- MINIMUM_GIT_VERSION =
Minimum git version required by this gem
Commands and features may require newer versions, but this is the absolute minimum supported version for the gem as a whole.
Version.parse('2.28.0')
- GitExecuteError =
Deprecated.
Use Git::Error instead
An alias for Git::Error
Git::GitExecuteError error class is an alias for Git::Error for backwards compatibility. It is recommended to use Git::Error directly.
ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Git::GitExecuteError', 'Git::Error', Git::Deprecation)
- VERSION =
The current gem version
'5.0.0.beta.1'- BRANCH_REFNAME_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.
Note:This regex is similar to Git::Branch::BRANCH_NAME_REGEXP but uses \A/\z anchors instead of ^/$ for stricter matching. As part of the architectural redesign, Git::Branch will eventually be refactored to use BranchInfo internally, at which point this will become the single source of truth for branch name parsing.
Note:This regex assumes remote names do not contain '/'. If a remote name contains '/', parsing will be incorrect. For example, 'remotes/team/upstream/main' would parse as remote_name='team' instead of 'team/upstream'. This is an inherent ambiguity in git refnames that can only be resolved with knowledge of configured remotes. See: https://github.com/ruby-git/ruby-git/issues/919
Regular expression for parsing branch refnames
Captures:
- remote_name: the remote name (e.g., 'origin') for remote branches, nil for local
- branch_name: the branch name without the remote prefix
%r{ \A # start of string (?:(?:refs/)?remotes/(?<remote_name>[^/]+)/)? # optional 'refs?/remotes/<remote_name>/' (?<branch_name>.+) # branch name (everything else) \z # end of string }x- CommandLineResult =
Backward-compatible alias for Git::CommandLine::Result
Git::CommandLine::Result
Instance Attribute Summary collapse
-
#author_date ⇒ String
readonly
The author date in ISO 8601 format.
-
#author_email ⇒ String
readonly
The email of the stash author.
-
#author_name ⇒ String
readonly
The name of the stash author.
-
#binary ⇒ Boolean
readonly
Whether this is a binary file.
-
#branch ⇒ String?
readonly
The branch name where the stash was created, or nil for custom stash messages.
-
#committer_date ⇒ String
readonly
The committer date in ISO 8601 format.
-
#committer_email ⇒ String
readonly
The email of the stash committer.
-
#committer_name ⇒ String
readonly
The name of the stash committer.
-
#current ⇒ Boolean
readonly
Whether this branch is currently checked out in the current worktree.
-
#deleted ⇒ Array<Git::BranchInfo>
readonly
Branches that were successfully deleted.
-
#deletions ⇒ Integer
readonly
Number of lines deleted.
-
#directory ⇒ String
readonly
The directory path (always ends with '/').
-
#dirstat ⇒ DirstatInfo?
readonly
Directory statistics if requested, nil otherwise.
-
#dst ⇒ FileRef?
readonly
The destination file reference, or nil for deleted files.
-
#entries ⇒ Array<DirstatEntry>
readonly
Directory statistics in order from git output.
-
#error_message ⇒ String
readonly
The error message from git explaining why the branch could not be deleted.
-
#file_patches ⇒ Array<FileDiffInfo>
readonly
Array of file diff info objects (empty if patch not requested).
-
#files ⇒ Array<DiffFileNumstatInfo, DiffFileRawInfo, DiffFilePatchInfo>
readonly
Per-file information.
-
#files_changed ⇒ Integer
readonly
Number of files changed (from --shortstat).
-
#index ⇒ Integer
readonly
The stash index (0, 1, 2, ...).
-
#insertions ⇒ Integer
readonly
Number of lines inserted.
-
#major ⇒ Integer
readonly
The major version number.
-
#message ⇒ String
readonly
The stash message (e.g., 'WIP on main: abc123 commit msg').
-
#minor ⇒ Integer
readonly
The minor version number.
-
#mode ⇒ String
readonly
The file mode (e.g., '100644' for regular files).
-
#name ⇒ String
readonly
The name of the branch that failed to be deleted.
-
#not_deleted ⇒ Array<Git::BranchDeleteFailure>
readonly
Branches that could not be deleted, with the reason for each failure.
-
#objecttype ⇒ String
readonly
'tag' for annotated tags, 'commit' for lightweight tags.
-
#oid ⇒ String
readonly
The full 40-character object identifier of the stash.
-
#patch ⇒ String
readonly
The full unified diff patch text for this file.
-
#path ⇒ String
readonly
The file path (destination path for renames).
-
#percentage ⇒ Float
readonly
The percentage of changes in this directory (0.0-100.0).
-
#refname ⇒ String
readonly
The full reference name of the branch.
-
#sha ⇒ String
readonly
The blob SHA (object identifier).
-
#short_oid ⇒ String
readonly
The abbreviated object identifier (typically 7 characters).
-
#similarity ⇒ Integer?
readonly
Similarity percentage for renames/copies (0-100), nil otherwise.
-
#src ⇒ FileRef?
readonly
The source file reference, or nil for new/added files.
-
#src_path ⇒ String?
readonly
The source path for renamed files, nil otherwise.
-
#stats ⇒ Hash
readonly
The statistics hash with :total and :files keys.
-
#status ⇒ Symbol
readonly
The change status (:added, :modified, :deleted, :renamed, :copied, :type_changed).
-
#symref ⇒ String?
readonly
The target reference if this is a symbolic reference.
-
#tagger_date ⇒ String?
readonly
The tag date in ISO 8601 format, or nil for lightweight tags.
-
#tagger_email ⇒ String?
readonly
The tagger's email, or nil for lightweight tags.
-
#tagger_name ⇒ String?
readonly
The tagger's name, or nil for lightweight tags.
-
#target_oid ⇒ String
readonly
The commit object ID (SHA) that HEAD points to.
-
#total_deletions ⇒ Integer
readonly
Total lines deleted across all files (from --shortstat).
-
#total_insertions ⇒ Integer
readonly
Total lines inserted across all files (from --shortstat).
-
#type ⇒ String
readonly
The type of change: 'modified', 'new', 'deleted', 'renamed'.
-
#upstream ⇒ Git::BranchInfo?
readonly
The configured upstream/tracking branch.
-
#worktree ⇒ Boolean
readonly
Whether this branch is checked out in another linked worktree.
Class Method Summary collapse
-
.bare(git_dir, options = {}) ⇒ Git::Base
Open a bare repository.
-
.binary_version(binary_path = Git::Base.config.binary_path) ⇒ Array<Integer>
deprecated
Deprecated.
Use Git.git_version instead, which returns a Version (not an Array). For the legacy array shape, call:
Git.git_version.to_a. The optional binary_path argument is preserved:Git.git_version(binary_path). -
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory.
- .config
- .configure {|Base.config| ... }
-
.default_branch(repository, options = {}) ⇒ String
Returns the name of the default branch of the given repository.
-
.export(repository, name, options = {})
Export the current HEAD (or a branch, if options[:branch] is specified) into the +name+ directory, then remove all traces of git from the directory.
-
.git_version(binary_path = nil) ⇒ Git::Version
Return the version of a git binary as a Version.
-
.global_config(name = nil, value = nil)
Same as g.config, but forces it to be at the global level.
-
.init(directory = '.', options = {}) ⇒ Git::Base
Create an empty Git repository or reinitialize an existing Git repository.
-
.ls_remote(location = nil, options = {}) ⇒ {String=>Hash}
returns a Hash containing information about the references of the target repository.
-
.open(working_dir, options = {}) ⇒ Git::Base
Open a an existing Git working directory.
Instance Method Summary collapse
-
#config(name = nil, value = nil)
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', 'email@email.com') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash.
- #global_config(name = nil, value = nil)
Instance Attribute Details
#author_date ⇒ String (readonly)
Returns the author date in ISO 8601 format.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#author_email ⇒ String (readonly)
Returns the email of the stash author.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#author_name ⇒ String (readonly)
Returns the name of the stash author.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#binary ⇒ Boolean (readonly)
Returns whether this is a binary file.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/diff_info.rb', line 45 FileDiffInfo = Data.define( :path, :patch, :mode, :src, :dst, :type, :binary ) do # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end end |
#branch ⇒ String? (readonly)
Returns the branch name where the stash was created, or nil for custom stash messages.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#committer_date ⇒ String (readonly)
Returns the committer date in ISO 8601 format.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#committer_email ⇒ String (readonly)
Returns the email of the stash committer.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#committer_name ⇒ String (readonly)
Returns the name of the stash committer.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#current ⇒ Boolean (readonly)
Whether this branch is currently checked out in the current worktree
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#deleted ⇒ Array<Git::BranchInfo> (readonly)
Branches that were successfully deleted
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/git/tag_delete_result.rb', line 45 TagDeleteResult = Data.define(:deleted, :not_deleted) do # Returns true if all requested tags were successfully deleted # # @return [Boolean] true if no tags failed to delete, false otherwise # # @example # result = tag_delete.call('v1.0.0') # if result.success? # puts "All tags deleted successfully" # else # puts "Some tags could not be deleted:" # result.not_deleted.each { |f| puts " #{f.name}: #{f.error_message}" } # end # def success? not_deleted.empty? end end |
#deletions ⇒ Integer (readonly)
Returns number of lines deleted.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/git/diff_file_raw_info.rb', line 67 DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do # Get the primary file path # # Returns the destination path if it exists, otherwise the source path. # This is the "current" or "canonical" path for the file. # # @return [String] the file path # def path dst&.path || src&.path end # Get the source path (for renames/copies) # # @return [String, nil] the source path, or nil if file was added # def src_path src&.path end # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end # Check if this file was renamed # # @return [Boolean] # def renamed? status == :renamed end # Check if this file was copied # # @return [Boolean] # def copied? status == :copied end # Check if this file was added # # @return [Boolean] # def added? status == :added end # Check if this file was deleted # # @return [Boolean] # def deleted? status == :deleted end end |
#directory ⇒ String (readonly)
Returns the directory path (always ends with '/').
19 |
# File 'lib/git/dirstat_info.rb', line 19 DirstatEntry = Data.define(:directory, :percentage) |
#dirstat ⇒ DirstatInfo? (readonly)
Returns directory statistics if requested, nil otherwise.
31 |
# File 'lib/git/diff_result.rb', line 31 DiffResult = Data.define(:files_changed, :total_insertions, :total_deletions, :files, :dirstat) |
#dst ⇒ FileRef? (readonly)
Returns the destination file reference, or nil for deleted files.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/diff_info.rb', line 45 FileDiffInfo = Data.define( :path, :patch, :mode, :src, :dst, :type, :binary ) do # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end end |
#entries ⇒ Array<DirstatEntry> (readonly)
Returns directory statistics in order from git output.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/git/dirstat_info.rb', line 41 DirstatInfo = Data.define(:entries) do # Look up percentage by directory path # # @param directory [String] the directory path # @return [Float, nil] the percentage or nil if not found # def [](directory) entries.find { |e| e.directory == directory }&.percentage end # Convert to a Hash mapping directory to percentage # # @return [Hash<String, Float>] # def to_h entries.to_h { |e| [e.directory, e.percentage] } end # Number of directories in the dirstat # # @return [Integer] # def size entries.size end # Check if dirstat is empty # # @return [Boolean] # def empty? entries.empty? end # Iterate over entries # # @yield [DirstatEntry] each entry # @return [Enumerator] if no block given # def each(&block) entries.each(&block) end include Enumerable end |
#error_message ⇒ String (readonly)
The error message from git explaining why the branch could not be deleted
30 |
# File 'lib/git/tag_delete_failure.rb', line 30 TagDeleteFailure = Data.define(:name, :error_message) |
#file_patches ⇒ Array<FileDiffInfo> (readonly)
Returns array of file diff info objects (empty if patch not requested).
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/git/diff_info.rb', line 99 DiffInfo = Data.define(:stats, :file_patches) do # @!method insertions # @return [Integer] total number of lines inserted # @!method deletions # @return [Integer] total number of lines deleted # @!method lines # @return [Integer] total number of lines changed (insertions + deletions) # @!method file_count # @return [Integer] number of files changed # Total number of lines inserted # # @return [Integer] # def insertions stats[:total][:insertions] end # Total number of lines deleted # # @return [Integer] # def deletions stats[:total][:deletions] end # Total number of lines changed (insertions + deletions) # # @return [Integer] # def lines stats[:total][:lines] end # Number of files changed # # @return [Integer] # def file_count stats[:total][:files] end # Per-file statistics hash # # @return [Hash<String, Hash>] mapping file paths to `{ insertions:, deletions: }` hashes # def file_stats stats[:files] end # Check if patch information is available # # @return [Boolean] true if file_patches were loaded # def patches? !file_patches.empty? end # Get patch info for a specific file # # @param path [String] the file path # @return [FileDiffInfo, nil] the diff info or nil if not found # def patch_for(path) file_patches.find { |p| p.path == path } end end |
#files ⇒ Array<DiffFileNumstatInfo, DiffFileRawInfo, DiffFilePatchInfo> (readonly)
Returns per-file information.
31 |
# File 'lib/git/diff_result.rb', line 31 DiffResult = Data.define(:files_changed, :total_insertions, :total_deletions, :files, :dirstat) |
#files_changed ⇒ Integer (readonly)
Returns number of files changed (from --shortstat).
31 |
# File 'lib/git/diff_result.rb', line 31 DiffResult = Data.define(:files_changed, :total_insertions, :total_deletions, :files, :dirstat) |
#index ⇒ Integer (readonly)
Returns the stash index (0, 1, 2, ...).
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#insertions ⇒ Integer (readonly)
Returns number of lines inserted.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/git/diff_file_raw_info.rb', line 67 DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do # Get the primary file path # # Returns the destination path if it exists, otherwise the source path. # This is the "current" or "canonical" path for the file. # # @return [String] the file path # def path dst&.path || src&.path end # Get the source path (for renames/copies) # # @return [String, nil] the source path, or nil if file was added # def src_path src&.path end # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end # Check if this file was renamed # # @return [Boolean] # def renamed? status == :renamed end # Check if this file was copied # # @return [Boolean] # def copied? status == :copied end # Check if this file was added # # @return [Boolean] # def added? status == :added end # Check if this file was deleted # # @return [Boolean] # def deleted? status == :deleted end end |
#major ⇒ Integer (readonly)
The major version number
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/git/version.rb', line 43 Version = Data.define(:major, :minor, :patch) do include Comparable # Parse a version string into a Version object # # Handles git's version output format, stripping platform suffixes # (like `.windows.1` or `.vfs.0`) and padding two-segment versions # to three segments. # # @example Parse various version string formats # Git::Version.parse('2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('git version 2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('2.42.0.windows.1') #=> Git::Version.new(2, 42, 0) # # @param string [String] version string to parse # # @return [Git::Version] the parsed version # # @raise [Git::UnexpectedResultError] if the string cannot be parsed as a version # def self.parse(string) version_match = string&.match(/(\d+)\.(\d+)(?:\.(\d+))?/) raise Git::UnexpectedResultError, "Invalid version: #{string.inspect}" unless version_match major = version_match[1].to_i minor = version_match[2].to_i patch = (version_match[3] || '0').to_i new(major, minor, patch) end # Compare this version to another # # @param other [Git::Version] the version to compare to # # @return [Integer] -1, 0, or 1 # def <=>(other) [major, minor, patch] <=> [other.major, other.minor, other.patch] end # Return the version as a dotted string # # @return [String] the version in "major.minor.patch" format # def to_s "#{major}.#{minor}.#{patch}" end # Return a readable representation # # @return [String] inspect string # def inspect "#<Git::Version #{self}>" end # Return the version as an array of integers # # Useful when legacy code expects the array shape returned by the # deprecated {Git::Lib#current_command_version} method. # # @return [Array<Integer>] [major, minor, patch] # # @example # Git.git_version.to_a #=> [2, 42, 0] # def to_a deconstruct end end |
#message ⇒ String (readonly)
Returns the stash message (e.g., 'WIP on main: abc123 commit msg').
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#minor ⇒ Integer (readonly)
The minor version number
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/git/version.rb', line 43 Version = Data.define(:major, :minor, :patch) do include Comparable # Parse a version string into a Version object # # Handles git's version output format, stripping platform suffixes # (like `.windows.1` or `.vfs.0`) and padding two-segment versions # to three segments. # # @example Parse various version string formats # Git::Version.parse('2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('git version 2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('2.42.0.windows.1') #=> Git::Version.new(2, 42, 0) # # @param string [String] version string to parse # # @return [Git::Version] the parsed version # # @raise [Git::UnexpectedResultError] if the string cannot be parsed as a version # def self.parse(string) version_match = string&.match(/(\d+)\.(\d+)(?:\.(\d+))?/) raise Git::UnexpectedResultError, "Invalid version: #{string.inspect}" unless version_match major = version_match[1].to_i minor = version_match[2].to_i patch = (version_match[3] || '0').to_i new(major, minor, patch) end # Compare this version to another # # @param other [Git::Version] the version to compare to # # @return [Integer] -1, 0, or 1 # def <=>(other) [major, minor, patch] <=> [other.major, other.minor, other.patch] end # Return the version as a dotted string # # @return [String] the version in "major.minor.patch" format # def to_s "#{major}.#{minor}.#{patch}" end # Return a readable representation # # @return [String] inspect string # def inspect "#<Git::Version #{self}>" end # Return the version as an array of integers # # Useful when legacy code expects the array shape returned by the # deprecated {Git::Lib#current_command_version} method. # # @return [Array<Integer>] [major, minor, patch] # # @example # Git.git_version.to_a #=> [2, 42, 0] # def to_a deconstruct end end |
#mode ⇒ String (readonly)
Returns the file mode (e.g., '100644' for regular files).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/git/file_ref.rb', line 33 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
#name ⇒ String (readonly)
The name of the branch that failed to be deleted
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#not_deleted ⇒ Array<Git::BranchDeleteFailure> (readonly)
Branches that could not be deleted, with the reason for each failure
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/git/tag_delete_result.rb', line 45 TagDeleteResult = Data.define(:deleted, :not_deleted) do # Returns true if all requested tags were successfully deleted # # @return [Boolean] true if no tags failed to delete, false otherwise # # @example # result = tag_delete.call('v1.0.0') # if result.success? # puts "All tags deleted successfully" # else # puts "Some tags could not be deleted:" # result.not_deleted.each { |f| puts " #{f.name}: #{f.error_message}" } # end # def success? not_deleted.empty? end end |
#objecttype ⇒ String (readonly)
Returns 'tag' for annotated tags, 'commit' for lightweight tags.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#oid ⇒ String (readonly)
Returns the full 40-character object identifier of the stash.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#patch ⇒ String (readonly)
Returns the full unified diff patch text for this file.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/git/version.rb', line 43 Version = Data.define(:major, :minor, :patch) do include Comparable # Parse a version string into a Version object # # Handles git's version output format, stripping platform suffixes # (like `.windows.1` or `.vfs.0`) and padding two-segment versions # to three segments. # # @example Parse various version string formats # Git::Version.parse('2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('git version 2.42.1') #=> Git::Version.new(2, 42, 1) # Git::Version.parse('2.42.0.windows.1') #=> Git::Version.new(2, 42, 0) # # @param string [String] version string to parse # # @return [Git::Version] the parsed version # # @raise [Git::UnexpectedResultError] if the string cannot be parsed as a version # def self.parse(string) version_match = string&.match(/(\d+)\.(\d+)(?:\.(\d+))?/) raise Git::UnexpectedResultError, "Invalid version: #{string.inspect}" unless version_match major = version_match[1].to_i minor = version_match[2].to_i patch = (version_match[3] || '0').to_i new(major, minor, patch) end # Compare this version to another # # @param other [Git::Version] the version to compare to # # @return [Integer] -1, 0, or 1 # def <=>(other) [major, minor, patch] <=> [other.major, other.minor, other.patch] end # Return the version as a dotted string # # @return [String] the version in "major.minor.patch" format # def to_s "#{major}.#{minor}.#{patch}" end # Return a readable representation # # @return [String] inspect string # def inspect "#<Git::Version #{self}>" end # Return the version as an array of integers # # Useful when legacy code expects the array shape returned by the # deprecated {Git::Lib#current_command_version} method. # # @return [Array<Integer>] [major, minor, patch] # # @example # Git.git_version.to_a #=> [2, 42, 0] # def to_a deconstruct end end |
#path ⇒ String (readonly)
Returns the file path (destination path for renames).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/git/file_ref.rb', line 33 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
#percentage ⇒ Float (readonly)
Returns the percentage of changes in this directory (0.0-100.0).
19 |
# File 'lib/git/dirstat_info.rb', line 19 DirstatEntry = Data.define(:directory, :percentage) |
#refname ⇒ String (readonly)
The full reference name of the branch
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#sha ⇒ String (readonly)
Returns the blob SHA (object identifier).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/git/file_ref.rb', line 33 FileRef = Data.define(:mode, :sha, :path) do # Check if this is a regular file (not executable, symlink, etc.) # # @return [Boolean] true if mode is 100644 # def regular_file? mode == '100644' end # Check if this is an executable file # # @return [Boolean] true if mode is 100755 # def executable? mode == '100755' end # Check if this is a symbolic link # # @return [Boolean] true if mode is 120000 # def symlink? mode == '120000' end # Return the mode as an integer (parsed as octal) # # Useful for bit operations on file permissions. # # @return [Integer] the mode as an integer # # @example Check file permissions # ref.mode_bits & 0o777 # => 0o644 (420 decimal) # # @example Check if group writable # (ref.mode_bits & 0o020) != 0 # def mode_bits mode.to_i(8) end end |
#short_oid ⇒ String (readonly)
Returns the abbreviated object identifier (typically 7 characters).
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/git/stash_info.rb', line 79 StashInfo = Data.define( :index, :name, :oid, :short_oid, :branch, :message, :author_name, :author_email, :author_date, :committer_name, :committer_email, :committer_date ) do # Returns the stash reference name # # @return [String] the stash name (e.g., 'stash@\\{0}') # # @example # info.to_s # => 'stash@{0}' # def to_s name end end |
#similarity ⇒ Integer? (readonly)
Returns similarity percentage for renames/copies (0-100), nil otherwise.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/git/diff_file_raw_info.rb', line 67 DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do # Get the primary file path # # Returns the destination path if it exists, otherwise the source path. # This is the "current" or "canonical" path for the file. # # @return [String] the file path # def path dst&.path || src&.path end # Get the source path (for renames/copies) # # @return [String, nil] the source path, or nil if file was added # def src_path src&.path end # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end # Check if this file was renamed # # @return [Boolean] # def renamed? status == :renamed end # Check if this file was copied # # @return [Boolean] # def copied? status == :copied end # Check if this file was added # # @return [Boolean] # def added? status == :added end # Check if this file was deleted # # @return [Boolean] # def deleted? status == :deleted end end |
#src ⇒ FileRef? (readonly)
Returns the source file reference, or nil for new/added files.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/diff_info.rb', line 45 FileDiffInfo = Data.define( :path, :patch, :mode, :src, :dst, :type, :binary ) do # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end end |
#src_path ⇒ String? (readonly)
Returns the source path for renamed files, nil otherwise.
20 21 22 23 24 25 26 27 28 |
# File 'lib/git/diff_file_numstat_info.rb', line 20 DiffFileNumstatInfo = Data.define(:path, :src_path, :insertions, :deletions) do # Check if this file was renamed # # @return [Boolean] true if the file was renamed # def renamed? !src_path.nil? end end |
#stats ⇒ Hash (readonly)
Returns the statistics hash with :total and :files keys.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/git/diff_info.rb', line 99 DiffInfo = Data.define(:stats, :file_patches) do # @!method insertions # @return [Integer] total number of lines inserted # @!method deletions # @return [Integer] total number of lines deleted # @!method lines # @return [Integer] total number of lines changed (insertions + deletions) # @!method file_count # @return [Integer] number of files changed # Total number of lines inserted # # @return [Integer] # def insertions stats[:total][:insertions] end # Total number of lines deleted # # @return [Integer] # def deletions stats[:total][:deletions] end # Total number of lines changed (insertions + deletions) # # @return [Integer] # def lines stats[:total][:lines] end # Number of files changed # # @return [Integer] # def file_count stats[:total][:files] end # Per-file statistics hash # # @return [Hash<String, Hash>] mapping file paths to `{ insertions:, deletions: }` hashes # def file_stats stats[:files] end # Check if patch information is available # # @return [Boolean] true if file_patches were loaded # def patches? !file_patches.empty? end # Get patch info for a specific file # # @param path [String] the file path # @return [FileDiffInfo, nil] the diff info or nil if not found # def patch_for(path) file_patches.find { |p| p.path == path } end end |
#status ⇒ Symbol (readonly)
Returns the change status (:added, :modified, :deleted, :renamed, :copied, :type_changed).
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/git/diff_file_raw_info.rb', line 67 DiffFileRawInfo = Data.define(:src, :dst, :status, :similarity, :insertions, :deletions, :binary) do # Get the primary file path # # Returns the destination path if it exists, otherwise the source path. # This is the "current" or "canonical" path for the file. # # @return [String] the file path # def path dst&.path || src&.path end # Get the source path (for renames/copies) # # @return [String, nil] the source path, or nil if file was added # def src_path src&.path end # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end # Check if this file was renamed # # @return [Boolean] # def renamed? status == :renamed end # Check if this file was copied # # @return [Boolean] # def copied? status == :copied end # Check if this file was added # # @return [Boolean] # def added? status == :added end # Check if this file was deleted # # @return [Boolean] # def deleted? status == :deleted end end |
#symref ⇒ String? (readonly)
The target reference if this is a symbolic reference
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#tagger_date ⇒ String? (readonly)
Returns the tag date in ISO 8601 format, or nil for lightweight tags.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#tagger_email ⇒ String? (readonly)
Returns the tagger's email, or nil for lightweight tags.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#tagger_name ⇒ String? (readonly)
Returns the tagger's name, or nil for lightweight tags.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#target_oid ⇒ String (readonly)
The commit object ID (SHA) that HEAD points to
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/git/tag_info.rb', line 79 TagInfo = Data.define(:name, :oid, :target_oid, :objecttype, :tagger_name, :tagger_email, :tagger_date, :message) do # @return [Boolean] true if this is an annotated tag (oid is present) def annotated? !oid.nil? end # @return [Boolean] true if this is a lightweight tag (oid is nil) def lightweight? oid.nil? end # Return the tagger as an Author object # # @return [Git::Author, nil] the tagger as an Author object, or nil for lightweight tags def tagger return nil unless annotated? && tagger_name && tagger_email # Git::Author expects format "Name <email> timestamp timezone" # We construct a minimal format that will parse correctly = Git::Author.new('') .name = tagger_name # Remove angle brackets if present .email = tagger_email.gsub(/\A<|>\z/, '') end end |
#total_deletions ⇒ Integer (readonly)
Returns total lines deleted across all files (from --shortstat).
31 |
# File 'lib/git/diff_result.rb', line 31 DiffResult = Data.define(:files_changed, :total_insertions, :total_deletions, :files, :dirstat) |
#total_insertions ⇒ Integer (readonly)
Returns total lines inserted across all files (from --shortstat).
31 |
# File 'lib/git/diff_result.rb', line 31 DiffResult = Data.define(:files_changed, :total_insertions, :total_deletions, :files, :dirstat) |
#type ⇒ String (readonly)
Returns the type of change: 'modified', 'new', 'deleted', 'renamed'.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/diff_info.rb', line 45 FileDiffInfo = Data.define( :path, :patch, :mode, :src, :dst, :type, :binary ) do # Check if this is a binary file # # @return [Boolean] true if the file is binary # def binary? binary end end |
#upstream ⇒ Git::BranchInfo? (readonly)
Remote-tracking branches (e.g., 'origin/main') have upstream: nil
When upstream exists but the remote-tracking branch hasn't been fetched, the upstream's target_oid may be nil
The configured upstream/tracking branch
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#worktree ⇒ Boolean (readonly)
Whether this branch is checked out in another linked worktree
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
Class Method Details
.bare(git_dir, options = {}) ⇒ Git::Base
Open a bare repository
Opens a bare repository located in the git_dir directory.
Since there is no working copy, you can not checkout or commit
but you can do most read operations.
136 137 138 |
# File 'lib/git.rb', line 136 def self.(git_dir, = {}) Base.(git_dir, ) end |
.binary_version(binary_path = Git::Base.config.binary_path) ⇒ Array<Integer>
Use git_version instead, which returns a Version (not an Array).
For the legacy array shape, call: Git.git_version.to_a.
The optional binary_path argument is preserved: Git.git_version(binary_path).
Return the version of the git binary
526 527 528 529 530 531 532 533 534 |
# File 'lib/git.rb', line 526 def self.binary_version(binary_path = Git::Base.config.binary_path) Git::Deprecation.warn( 'Git.binary_version is deprecated and will be removed in 6.0. ' \ 'Use Git.git_version instead, which returns a Git::Version ' \ '(not an Array). For the legacy array shape, call: Git.git_version.to_a. ' \ 'The optional binary_path argument is preserved: Git.git_version(binary_path).' ) git_version(binary_path).to_a end |
.clone(repository_url, directory = nil, options = {}) ⇒ Git::Base
Clone a repository into an empty or newly created directory
254 255 256 |
# File 'lib/git.rb', line 254 def self.clone(repository_url, directory = nil, = {}) Base.clone(repository_url, directory, ) end |
.configure {|Base.config| ... }
90 91 92 |
# File 'lib/git.rb', line 90 def self.configure yield Base.config end |
.default_branch(repository, options = {}) ⇒ String
Returns the name of the default branch of the given repository
295 296 297 |
# File 'lib/git.rb', line 295 def self.default_branch(repository, = {}) Base.repository_default_branch(repository, ) end |
.export(repository, name, options = {})
Export the current HEAD (or a branch, if options[:branch] is specified) into the +name+ directory, then remove all traces of git from the directory.
See +clone+ for options. Does not obey the :remote option, since the .git info will be deleted anyway; always uses the default remote, 'origin.'
306 307 308 309 310 311 |
# File 'lib/git.rb', line 306 def self.export(repository, name, = {}) .delete(:remote) repo = clone(repository, name, { depth: 1 }.merge()) repo.checkout("origin/#{[:branch]}") if [:branch] FileUtils.rm_r File.join(repo.dir.to_s, '.git') end |
.git_version(binary_path = nil) ⇒ Git::Version
Return the version of a git binary as a Version
503 504 505 506 |
# File 'lib/git.rb', line 503 def self.git_version(binary_path = nil) path = binary_path || Git::Base.config.binary_path Git::Lib.cached_git_version(path) { run_git_version(path) } end |
.global_config(name = nil, value = nil)
Same as g.config, but forces it to be at the global level
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', 'email@email.com') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash
319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/git.rb', line 319 def self.global_config(name = nil, value = nil) lib = Git::Lib.new(nil, nil) if name && value # set value lib.global_config_set(name, value) elsif name # return value lib.global_config_get(name) else # return hash lib.global_config_list end end |
.init(directory = '.', options = {}) ⇒ Git::Base
Create an empty Git repository or reinitialize an existing Git repository
391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/git.rb', line 391 def self.init(directory = '.', = {}) require_relative 'git/commands/init' = .dup [:repository] ||= .delete(:separate_git_dir) init_opts = .slice(:bare, :initial_branch) init_opts[:separate_git_dir] = [:repository] if .key?(:repository) Git::Commands::Init.new(Git::Lib.new(nil, [:log])).call(directory, **init_opts) open_initialized_repository(directory, ) end |
.ls_remote(location = nil, options = {}) ⇒ {String=>Hash}
returns a Hash containing information about the references of the target repository
options :refs
426 427 428 |
# File 'lib/git.rb', line 426 def self.ls_remote(location = nil, = {}) Git::Lib.new.ls_remote(location, ) end |
.open(working_dir, options = {}) ⇒ Git::Base
Open a an existing Git working directory
Git.open will most likely be the most common way to create a git reference, referring to an existing working directory.
If not provided in the options, the library will assume
the repository and index are in the default places (.git/, .git/index).
480 481 482 |
# File 'lib/git.rb', line 480 def self.open(working_dir, = {}) Base.open(working_dir, ) end |
Instance Method Details
#config(name = nil, value = nil)
g.config('user.name', 'Scott Chacon') # sets value g.config('user.email', 'email@email.com') # sets value g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/git.rb', line 76 def config(name = nil, value = nil) lib = Git::Lib.new if name && value # set value lib.config_set(name, value) elsif name # return value lib.config_get(name) else # return hash lib.config_list end end |
#global_config(name = nil, value = nil)
98 99 100 |
# File 'lib/git.rb', line 98 def global_config(name = nil, value = nil) self.class.global_config(name, value) end |