allow running "git cl format" from subdirectories

BUG=

Review URL: https://chromiumcodereview.appspot.com/22308002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@215724 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index 64ebcd9..156d28a 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2121,13 +2121,16 @@
   diff_cmd += ['*' + ext for ext in CLANG_EXTS]
   diff_output = RunGit(diff_cmd)
 
+  top_dir = RunGit(["rev-parse", "--show-toplevel"]).rstrip('\n')
+
   if opts.full:
     # diff_output is a list of files to send to clang-format.
     files = diff_output.splitlines()
     if not files:
       print "Nothing to format."
       return 0
-    RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files)
+    RunCommand(['clang-format', '-i', '-style', 'Chromium'] + files,
+               cwd=top_dir)
   else:
     # diff_output is a patch to send to clang-format-diff.py
     cfd_path = os.path.join('/usr', 'lib', 'clang-format',
@@ -2135,7 +2138,7 @@
     if not os.path.exists(cfd_path):
       DieWithError('Could not find clang-format-diff at %s.' % cfd_path)
     cmd = [sys.executable, cfd_path, '-style', 'Chromium']
-    RunCommand(cmd, stdin=diff_output)
+    RunCommand(cmd, stdin=diff_output, cwd=top_dir)
 
   return 0