Skip to content

Commit f1fd9d5

Browse files
committed
Merge pull request #94 from danvk/track-simple-invokation
Track whether webdiff was invoked from HEAD
2 parents aaf0fb0 + 9a37304 commit f1fd9d5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

webdiff/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ def abs_path(path):
219219
return os.path.join(os.getcwd(), path)
220220

221221

222+
def is_webdiff_from_head():
223+
'''Was webdiff invoked as `git webdiff` with no other non-flag args?'''
224+
return os.environ.get('WEBDIFF_FROM_HEAD') != None
225+
226+
222227
def run():
223228
global A_DIR, B_DIR, DIFF, PORT
224229
try:

webdiff/gitwebdiff.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/usr/bin/env python
22
'''This lets you run "git webdiff" instead of "git difftool".'''
33

4+
import os
45
import subprocess
56
import sys
67

8+
9+
def any_nonflag_args(args):
10+
"""Do any args not start with '-'? If so, this isn't a HEAD diff."""
11+
return len([x for x in args if not x.startswith('-')]) > 0
12+
13+
714
def run():
15+
if not any_nonflag_args(sys.argv[1:]):
16+
# This tells webdiff that it was invoked as a simple "git webdiff", not
17+
# "git webdiff <sha>". This allows special treatment (e.g. for
18+
# staging diffhunks).
19+
os.environ['WEBDIFF_FROM_HEAD'] = 'yes'
20+
821
sys.exit(subprocess.call(
922
'git difftool -d -x webdiff'.split(' ') + sys.argv[1:]))
1023

0 commit comments

Comments
 (0)