Skip to content
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

rely on git rev-parse --git-dir etc to find git dir reliably #345

Open
mroth opened this issue May 17, 2017 · 1 comment
Open

rely on git rev-parse --git-dir etc to find git dir reliably #345

mroth opened this issue May 17, 2017 · 1 comment
Labels

Comments

@mroth
Copy link
Member

mroth commented May 17, 2017

Currently in the CLI we have this fun snippet, designed to handle the case where you are in a subdirectory of a git repo and want to do a lolcommits command:

      def self.change_dir_to_root_or_repo!
        debug 'Walking up dir tree'
        loop do
          cur = File.expand_path('.')
          nxt = File.expand_path('..', cur)
          if nxt == cur
            warn 'Repository root not found'
            return
          end
          return if VCSInfo.repo_root?
          Dir.chdir(nxt)
        end
      end

This is actually invoked as part of the CLI logic, and the main library just assumes the PWD is in the correct place.

Rather, instead of manually walking the directory hierarchy upwards, we should use the built-in VCS support in both git and hg to determine the proper paths. This could/should be handled transparently in the lib/backends library, outside of the CLI, so things "just work" when using lolcommits as an API.

For reference, the commands we would probably be utilizing are:

  • git rev-parse --show-toplevel
  • git rev-parse --git-dir
  • hg root

This will have the added benefit of making lolcommits work with git submodules (which store their info somewhere else besides PWD/.git, but --git-dir will find it successfully.)

@mroth mroth added the refactor label May 17, 2017
@matthutchinson
Copy link
Member

👍 Good idea, the mercurial and git gems we currently use might already have helpers for those commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants