From c3b3dc0183000e2ee6e1759bdaf44bcbcadef3c1 Mon Sep 17 00:00:00 2001 From: "mdempsky@google.com" Date: Mon, 5 Aug 2013 23:09:49 +0000 Subject: [PATCH] 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 --- git_cl.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index 64ebcd9e4..156d28a6e 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2121,13 +2121,16 @@ def CMDformat(parser, args): 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 @@ def CMDformat(parser, args): 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