From ae843c8aadfa530742e95f1c4c8e1f449fe84d01 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 9 Dec 2007 13:22:19 -0800 Subject: [PATCH] Added support for renamed file detection in cmds.git_status() - cmds.git_status now includes a regex for renamed files - renamed files are listed twice in the staged list: once for the deleted file and once for the new filename - cmds.git_status's other regexes were also fixed to not require the filename to be lstrip()'d Signed-off by: David Aguilar --- .gitignore | 2 +- py/cmds.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f3a702b..0e44c71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /Makefile /build -/install +/installroot /.lock-wscript *.pyo *.pyc diff --git a/py/cmds.py b/py/cmds.py index 48fb102..9c4f60e 100644 --- a/py/cmds.py +++ b/py/cmds.py @@ -235,7 +235,11 @@ def git_status(): untracked_header_seen = False modified_header = '# Changed but not updated:' - modified_regex = re.compile('(#\tmodified:|#\tnew file:|#\tdeleted:)') + modified_regex = re.compile ('(#\tmodified:\W{3}' + + '|#\tnew file:\W{3}' + + '|#\tdeleted:\W{4})') + + renamed_regex = re.compile ('(#\trenamed:\W{4})(.*?)\W->\W(.*)') untracked_header = '# Untracked files:' untracked_regex = re.compile ('#\t(.+)') @@ -244,6 +248,7 @@ def git_status(): unstaged = [] untracked = [] + # Untracked files for status_line in status_lines: if untracked_header in status_line: untracked_header_seen = True @@ -255,6 +260,7 @@ def git_status(): filename = match.group (1) untracked.append (filename) + # Staged, unstaged, and renamed files for status_line in status_lines: if modified_header in status_line: unstaged_header_seen = True @@ -264,8 +270,16 @@ def git_status(): tag = match.group (0) filename = status_line.replace (tag, '') if unstaged_header_seen: - unstaged.append (filename.lstrip()) + unstaged.append (filename) else: - staged.append (filename.lstrip()) + staged.append (filename) + continue + # Renamed files + match = renamed_regex.match (status_line) + if match: + oldname = match.group (2) + newname = match.group (3) + staged.append (oldname) + staged.append (newname) return ( staged, unstaged, untracked ) -- 2.11.4.GIT