Class: QuietQuality::VersionControlSystems::Git
- Inherits:
-
Object
- Object
- QuietQuality::VersionControlSystems::Git
- Defined in:
- lib/quiet_quality/version_control_systems/git.rb
Constant Summary collapse
- Error =
Class.new(VersionControlSystems::Error)
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.default_branch(remote:) ⇒ String
The default branch for the given remote.
Instance Method Summary collapse
-
#changed_files(base: nil, sha: "HEAD", include_uncommitted: true, include_untracked: false) ⇒ Hash
Retrieves the files changed in the given commit compared to the base.
-
#comparison_base(sha:, comparison_branch:) ⇒ String
Determines the nearest common ancestor for the given ‘sha` compared to the `branch`.
-
#default_branch ⇒ String
The default branch for the default remote for the local git repository.
-
#initialize(path = ".") ⇒ Git
constructor
Initializer.
Constructor Details
#initialize(path = ".") ⇒ Git
Initializer
13 14 15 16 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 13 def initialize(path = ".") @path = path @git = ::Git.open(path) end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
6 7 8 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 6 def git @git end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 6 def path @path end |
Class Method Details
.default_branch(remote:) ⇒ String
The default branch for the given remote
51 52 53 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 51 def self.default_branch(remote:) ::Git.default_branch(remote) end |
Instance Method Details
#changed_files(base: nil, sha: "HEAD", include_uncommitted: true, include_untracked: false) ⇒ Hash
Retrieves the files changed in the given commit compared to the base. When no base is given, the default branch is used as the base. When no sha is given, the HEAD commit is used. Optionally, uncommitted changes can be included in the result, as well as untracked files.
28 29 30 31 32 33 34 35 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 28 def changed_files(base: nil, sha: "HEAD", include_uncommitted: true, include_untracked: false) base_commit = comparison_base(sha: sha, comparison_branch: base || default_branch) [ committed_changed_files(base_commit, sha), include_uncommitted ? uncommitted_changed_files : nil, include_untracked ? untracked_changed_files : nil ].compact.reduce(&:merge) end |
#comparison_base(sha:, comparison_branch:) ⇒ String
Determines the nearest common ancestor for the given ‘sha` compared to the `branch`.
63 64 65 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 63 def comparison_base(sha:, comparison_branch:) git.merge_base(comparison_branch, sha).first.sha end |
#default_branch ⇒ String
The default branch for the default remote for the local git repository
41 42 43 |
# File 'lib/quiet_quality/version_control_systems/git.rb', line 41 def default_branch self.class.default_branch(remote: git.remote.url) end |