Skip to content

Allow to setup logger while Git.clone #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

gigorok
Copy link

@gigorok gigorok commented Dec 9, 2020

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

Description

Add new optional option log to Git.clone to make possible to pass own logger

Signed-off-by: Igor Gonchar <igor.gonchar@gmail.com>
@gigorok gigorok changed the title allow to setup logger while git clone Allow to setup logger while Git.clone Dec 9, 2020
@gigorok gigorok marked this pull request as ready for review December 9, 2020 10:56
@jcouball
Copy link
Member

jcouball commented Dec 21, 2020

Wow! Your change works but the logic is twisted because of the way the Lib and Base classes work (?) together. Not your fault. I think the division of labor between Git::Base and Git::Lib is not right. i.e. the abstraction is wrong.

One question I have is what is the purpose of the return result of Git::Lib#clone? It seems to be to return the opts needed to pass to Git::Base.new. If that is the case, maybe it would be best to add the logger there AND make it more explicit what the return value is intended for.

Here is my untested version of this change. I have elided the main body of Git::Lib.clone which would remain unchanged.

What do you think?

module Git
  class Base
    def self.clone(repository, name, opts = {})
      self.new(Git::Lib.new(nil, opts[:log]).clone(repository, name, opts))
    end
  end

  class Lib
    def clone(...)
      ...
      return_base_opts_from_clone(clone_dir, opts)
    end

    private:

    # Build the opts hash needed for Git::Base.new based on the clone command
    #
    def return_base_opts_from_clone(clone_dir, opts)
      base_opts = {}
      base_opts[:repository] = clone_dir if (opts[:bare] || opts[:mirror])
      base_opts[:working_directory] = clone_dir unless (opts[:bare] || opts[:mirror])
      base_opts[:log] = opts[:log] if opts[:log]
      base_opts
    end
  end
end

This makes it clear that there is an unhealthy circular dependency between Git::Base and Git::Lib. I think making it more explicit is a good step in the right direction.

One last thing. There should really be a test that shows that calling Git.clone with :log in options results in an object that has its logger set appropriately. I am happy to help with the test if needed.

@jcouball
Copy link
Member

@gigorok I have submitted PR #501 with the changes I suggested. Please give a +1 there if you like it.

@gigorok
Copy link
Author

gigorok commented Dec 23, 2020

Hey @jcouball
Your suggestion #501 will be better. I like it.
Thanks for your help!

@jcouball
Copy link
Member

Thanks @gigorok. Closing this PR in favor of PR #501.

@jcouball jcouball closed this Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants