From 13f9c37185750d4212a125204d22302376c77f8e Mon Sep 17 00:00:00 2001 From: hanpfei Date: Mon, 8 Aug 2016 22:05:56 -0700 Subject: [PATCH] Update top_dir with git repo root just when cwd locate in a git repo. if when execute command "git rev-parse --show-toplevel" in a directory that is not a subdirectory of a git repo, CheckCallAndFilter will not throw exception, so the top_dir may be updated with a invalid path. BUG=633971 Signed-off-by: hanpfei Review-Url: https://codereview.chromium.org/2200193003 --- gclient_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gclient_utils.py b/gclient_utils.py index 76cbe2df1d..a988b82426 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -671,7 +671,9 @@ def GetPrimarySolutionPath(): # checkout. top_dir = [os.getcwd()] def filter_fn(line): - top_dir[0] = os.path.normpath(line.rstrip('\n')) + repo_root_path = os.path.normpath(line.rstrip('\n')) + if os.path.exists(repo_root_path): + top_dir[0] = repo_root_path try: CheckCallAndFilter(["git", "rev-parse", "--show-toplevel"], print_stdout=False, filter_fn=filter_fn)