Class: Giblish::GitCheckoutManager
- Inherits:
-
Object
- Object
- Giblish::GitCheckoutManager
- Defined in:
- lib/giblish/gitrepos/checkoutmanager.rb
Overview
acquires a handle to an existing git repo and provide the user with a iteration method 'each_checkout' where each matching branch and/or tag is checked out and presented to the user code.
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#git_repo ⇒ Object
readonly
Returns the value of attribute git_repo.
-
#repo_root ⇒ Object
readonly
Returns the value of attribute repo_root.
-
#summary_provider ⇒ Object
readonly
Returns the value of attribute summary_provider.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#each_checkout ⇒ Object
present each git checkout matching the init criteria to the user's code.
-
#initialize(cmd_opts) ⇒ GitCheckoutManager
constructor
- cmd_opts
a CmdLine::Options instance.
Constructor Details
#initialize(cmd_opts) ⇒ GitCheckoutManager
- cmd_opts
a CmdLine::Options instance
Required options:
- srcdir
Pathname to the top dir of the local git repo to work with
- local_only
if true, do not try to access any remote branches or merge with any upstream changes
Optional options:
- abort_on_error
bail out at an error or continue. Default 'true'
- branch_regex
the regex for the branches to include during iteration (default: none)
- tag_regex
the regex for the tags to include during iteration (default: none)
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 25 def initialize(cmd_opts) @repo_root = GitItf.find_gitrepo_root(cmd_opts.srcdir) raise ArgumentError, "The path: #{cmd_opts.srcdir} is not within a git repo!" if @repo_root.nil? @local_only = cmd_opts.local_only @abort_on_error = cmd_opts.abort_on_error.nil? || cmd_opts.abort_on_error @git_repo = init_git_repo(@repo_root, @local_only) @branches = select_user_branches(cmd_opts.branch_regex, @local_only) @tags = (cmd_opts.tag_regex) @summary_provider = GitSummaryDataProvider.new(@repo_root.basename) end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
13 14 15 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 13 def branches @branches end |
#git_repo ⇒ Object (readonly)
Returns the value of attribute git_repo.
13 14 15 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 13 def git_repo @git_repo end |
#repo_root ⇒ Object (readonly)
Returns the value of attribute repo_root.
13 14 15 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 13 def repo_root @repo_root end |
#summary_provider ⇒ Object (readonly)
Returns the value of attribute summary_provider.
13 14 15 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 13 def summary_provider @summary_provider end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
13 14 15 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 13 def @tags end |
Instance Method Details
#each_checkout ⇒ Object
present each git checkout matching the init criteria to the user's code.
Example
gcm = GitCheckoutManager.new(opts) gcm.each_checkout do |name| ... do things with the currently checked out working tree ... end
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/giblish/gitrepos/checkoutmanager.rb', line 46 def each_checkout current_branch = @git_repo.current_branch checkouts = (@branches + @tags) if checkouts.empty? Giblog.logger.info { "No matching branches or tags found." } return end checkouts.each do |treeish| sync_treeish(treeish) # cache branch/tag info for downstream content generation @summary_provider.cache_info(@git_repo, treeish) yield(treeish.name) rescue => e Giblog.logger.error { e. } raise e if @abort_on_error end if @git_repo.current_branch != current_branch Giblog.logger.info { "Checking out '#{current_branch}'" } @git_repo.checkout current_branch end end |