From e4af1ab4cf091c5cc4530de8784653bd351acb53 Mon Sep 17 00:00:00 2001 From: "msb@chromium.org" Date: Wed, 13 Jan 2010 21:26:09 +0000 Subject: [PATCH] gclient: Add better error reporting when path is not a git repo. Review URL: http://codereview.chromium.org/505007 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@36172 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_scm.py | 8 ++++++++ tests/gclient_scm_test.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gclient_scm.py b/gclient_scm.py index 23a510857..010c45d18 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -187,6 +187,14 @@ class GitWrapper(SCMWrapper, scm.GIT): file_list.extend([os.path.join(self.checkout_path, f) for f in files]) return + if not os.path.exists(os.path.join(self.checkout_path, '.git')): + raise gclient_utils.Error('\n____ %s%s\n' + '\tPath is not a git repo. No .git dir.\n' + '\tTo resolve:\n' + '\t\trm -rf %s\n' + '\tAnd run gclient sync again\n' + % (self.relpath, rev_str, self.relpath)) + new_base = 'origin' if revision: new_base = revision diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 66c1f5e3b..61146b4a4 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -16,6 +16,7 @@ """Unit tests for gclient_scm.py.""" +import os import shutil # Import it before super_mox to keep a valid reference. from subprocess import Popen, PIPE, STDOUT @@ -541,6 +542,22 @@ from :3 '\tSee man git-rebase for details.\n' self.assertRaisesError(exception, scm.update, options, (), []) + def testUpdateNotGit(self): + if not self.enabled: + return + options = self.Options() + scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, + relpath=self.relpath) + git_path = gclient_scm.os.path.join(self.base_path, '.git') + os.rename(git_path, git_path + 'foo') + exception = \ + '\n____ .\n' \ + '\tPath is not a git repo. No .git dir.\n' \ + '\tTo resolve:\n' \ + '\t\trm -rf .\n' \ + '\tAnd run gclient sync again\n' + self.assertRaisesError(exception, scm.update, options, (), []) + def testRevinfo(self): if not self.enabled: return