Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: tools/git-sync-deps

Issue 245503003: git-sync-deps verifies that directory is a top-level git directory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/git-sync-deps
diff --git a/tools/git-sync-deps b/tools/git-sync-deps
index 7a305f493bd8894be0a9a329ac1d9bd2db6949e0..8edc0c36c71ea9dfb85a90f11d1ad374235e2ec7 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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698