Class: Git::Log
- Inherits:
-
Object
- Object
- Git::Log
- Defined in:
- lib/git/log.rb
Overview
Builds and executes a git log query
This class provides a fluent interface for building complex git log queries.
Queries default to returning 30 commits; call #max_count with :all to
return every matching commit. Calling #all adds the --all flag to include
all refs in the search but does not change the number of commits returned.
The query runs when #execute is called and returns a Result holding the matching commits.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#all ⇒ Git::Log
Includes commits reachable from all refs.
-
#author(regex) ⇒ Git::Log
Filters commits by author pattern.
-
#between(val1, val2 = nil) ⇒ Git::Log
Limits commits to the given revision range.
-
#cherry ⇒ Git::Log
Omits commits equivalent to cherry-picked commits.
-
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object.
-
#grep(regex) ⇒ Git::Log
Filters commits by commit message pattern.
-
#initialize(base, max_count = 30) ⇒ Log
constructor
Create a new Git::Log object.
-
#max_count(num) ⇒ Git::Log
Set query options using a fluent interface.
-
#merges ⇒ Git::Log
Includes only merge commits.
-
#object(objectish) ⇒ Git::Log
Sets the revision range expression for the log query.
-
#path(path) ⇒ Git::Log
Limits commits to those that touch the given path or paths.
- #perl_regexp ⇒ Git::Log
-
#since(date) ⇒ Git::Log
Includes only commits newer than the given date expression.
-
#skip(num) ⇒ Git::Log
Skips a number of commits before returning results.
-
#until(date) ⇒ Git::Log
Includes only commits older than the given date expression.
Constructor Details
#initialize(base, max_count = 30) ⇒ Log
Create a new Git::Log object
94 95 96 97 98 99 |
# File 'lib/git/log.rb', line 94 def initialize(base, max_count = 30) @base = base @options = {} @dirty = true self.max_count(max_count) end |
Instance Method Details
#all ⇒ Git::Log
Includes commits reachable from all refs
117 |
# File 'lib/git/log.rb', line 117 def all = set_option(:all, true) |
#author(regex) ⇒ Git::Log
Filters commits by author pattern
133 |
# File 'lib/git/log.rb', line 133 def (regex) = set_option(:author, regex) |
#between(val1, val2 = nil) ⇒ Git::Log
Limits commits to the given revision range
203 |
# File 'lib/git/log.rb', line 203 def between(val1, val2 = nil) = set_option(:between, [val1, val2]) |
#cherry ⇒ Git::Log
Omits commits equivalent to cherry-picked commits
209 |
# File 'lib/git/log.rb', line 209 def cherry = set_option(:cherry, true) |
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object
This is the preferred way to get log data. It separates the query building from the execution, making the API more predictable.
232 233 234 235 |
# File 'lib/git/log.rb', line 232 def execute run_log_if_dirty Result.new(@commits) end |
#grep(regex) ⇒ Git::Log
Filters commits by commit message pattern
141 |
# File 'lib/git/log.rb', line 141 def grep(regex) = set_option(:grep, regex) |
#max_count(num) ⇒ Git::Log
Set query options using a fluent interface.
Each method returns self to allow for chaining.
Sets the maximum number of commits to return
111 |
# File 'lib/git/log.rb', line 111 def max_count(num) = set_option(:count, num == :all ? nil : num) |
#merges ⇒ Git::Log
Includes only merge commits
215 |
# File 'lib/git/log.rb', line 215 def merges = set_option(:merges, true) |
#object(objectish) ⇒ Git::Log
Sets the revision range expression for the log query
125 |
# File 'lib/git/log.rb', line 125 def object(objectish) = set_option(:object, objectish) |
#path(path) ⇒ Git::Log
Limits commits to those that touch the given path or paths
168 |
# File 'lib/git/log.rb', line 168 def path(path) = set_option(:path_limiter, path) |
#perl_regexp ⇒ Git::Log
On Git for Windows, git's default regex engine matches bytes rather
than characters, so a metacharacter such as . or a POSIX class such as
[[:alpha:]] never matches a whole multi-byte character. The match fails
silently: git exits zero and the result is empty. PCRE does match characters
on that platform, but it is a different dialect than git's default, so
selecting it is a deliberate choice by the caller.
Interprets #grep and #author patterns as Perl-compatible regular expressions
Selects PCRE instead of git's default POSIX basic regular expressions for every pattern in the query. Requires a git built with PCRE support.
160 |
# File 'lib/git/log.rb', line 160 def perl_regexp = set_option(:perl_regexp, true) |
#since(date) ⇒ Git::Log
Includes only commits newer than the given date expression
184 |
# File 'lib/git/log.rb', line 184 def since(date) = set_option(:since, date) |
#skip(num) ⇒ Git::Log
Skips a number of commits before returning results
176 |
# File 'lib/git/log.rb', line 176 def skip(num) = set_option(:skip, num) |
#until(date) ⇒ Git::Log
Includes only commits older than the given date expression
192 |
# File 'lib/git/log.rb', line 192 def until(date) = set_option(:until, date) |