diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-21 19:03:05 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-21 19:03:05 +0000 |
commit | aae6e6f0439984a8c9a541fac6d6f8af2e417735 (patch) | |
tree | 9b4d379af67f2e045caade7708216f5e6a5b588f /tools/git-sync-deps | |
parent | f1e9d4719fcd61ac619626a35549995cad8efc21 (diff) |
git-sync-deps verifies that directory is a top-level git directory.
NOTRY=true
R=mtklein@google.com
Author: halcanary@google.com
Review URL: https://codereview.chromium.org/245503003
git-svn-id: http://skia.googlecode.com/svn/trunk@14285 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/git-sync-deps')
-rwxr-xr-x | tools/git-sync-deps | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/git-sync-deps b/tools/git-sync-deps index 7a305f493b..8edc0c36c7 100755 --- a/tools/git-sync-deps +++ b/tools/git-sync-deps @@ -64,6 +64,23 @@ def git_repository_sync_is_disabled(git, directory): return False +def is_git_toplevel(git, directory): + """Return true iff the directory is the top level of a Git repository. + + Args: + git (string) the git executable + + directory (string) the path into which the repository + is expected to be checked out. + """ + try: + toplevel = subprocess.check_output( + [git, 'rev-parse', '--show-toplevel'], cwd=directory).strip() + return os.path.abspath(directory) == os.path.abspath(toplevel) + except subprocess.CalledProcessError: + return False + + def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): """Checkout (and clone if needed) a Git repository. @@ -87,6 +104,12 @@ def git_checkout_to_directory(git, repo, checkoutable, directory, verbose): subprocess.check_call( [git, 'clone', '--quiet', repo, directory]) + if not is_git_toplevel(git, directory): + # if the directory exists, but isn't a git repo, you will modify + # the parent repostory, which isn't what you want. + sys.stdout.write('%s\n IS NOT TOP-LEVEL GIT DIRECTORY.\n' % directory) + return + # Check to see if this repo is disabled. Quick return. if git_repository_sync_is_disabled(git, directory): sys.stdout.write('%s\n SYNC IS DISABLED.\n' % directory) |