From 90e137a64f3fd647c78f39b8e73fae2cfd23eef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Mon, 24 Oct 2011 01:11:43 +0200 Subject: [PATCH] improve detecting whether we are currently in a git repo --- lib/hub/context.rb | 16 ++++++++-------- test/hub_test.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/hub/context.rb b/lib/hub/context.rb index a7816e78..0ee1cde0 100644 --- a/lib/hub/context.rb +++ b/lib/hub/context.rb @@ -123,14 +123,6 @@ module Hub GIT_CONFIG["config alias.#{name}"] end - # Core.repositoryformatversion should exist for all git - # repositories, and be blank for all non-git repositories. If - # there's a better config setting to check here, this can be - # changed without breaking anything. - def is_repo? - GIT_CONFIG['config core.repositoryformatversion'] - end - def github_url(options = {}) repo = options[:repo] user, repo = repo.split('/') if repo && repo.index('/') @@ -169,6 +161,14 @@ module Hub DIRNAME end + def git_dir + GIT_CONFIG['rev-parse --git-dir'] + end + + def is_repo? + !!git_dir + end + # Cross-platform web browser command; respects the value set in $BROWSER. # # Returns an array, e.g.: ['open'] diff --git a/test/hub_test.rb b/test/hub_test.rb index 5b80b160..9295557f 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -46,7 +46,7 @@ class HubTest < Test::Unit::TestCase 'config branch.master.remote' => 'origin', 'config branch.master.merge' => 'refs/heads/master', 'config --bool hub.http-clone' => 'false', - 'config core.repositoryformatversion' => '0' + 'rev-parse --git-dir' => '.git' ) super end -- GitLab