Fix git freeze command
When a repo has both staged and unstaged changes for a same file, `git
freeze` doesn't work as intended. It freezes only the indexed changes
and has to be run twice to achieve the intended results. This change
fixes this case.
Change-Id: Ie620a111c4a6f721bf6c85200cb05676022041a1
Bug: 1476516
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4820460
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
diff --git a/git_common.py b/git_common.py
index e559437..d406dc4 100644
--- a/git_common.py
+++ b/git_common.py
@@ -479,8 +479,16 @@
# added yet.
# lstat = '?' means that the file is untracked.
have_indexed_files = True
+
+ # If the file has both indexed and unindexed changes.
+ # rstat shows the status of the working tree. If the file also has changes
+ # in the working tree, it should be tracked both in indexed and unindexed
+ # changes.
+ if s.rstat != ' ':
+ unindexed.append(f.encode('utf-8'))
else:
unindexed.append(f.encode('utf-8'))
+
if s.lstat == '?' and limit_mb > 0:
untracked_bytes += os.lstat(os.path.join(root_path, f)).st_size
@@ -903,7 +911,7 @@
Returns a generator of (current_name, (lstat, rstat, src)) pairs where:
* current_name is the name of the file
* lstat is the left status code letter from git-status
- * rstat is the left status code letter from git-status
+ * rstat is the right status code letter from git-status
* src is the current name of the file, or the original name of the file
if lstat == 'R'
"""