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>
This commit is contained in:
Aravind Vasudevan
2023-08-29 23:02:15 +00:00
committed by LUCI CQ
parent f2436fce33
commit c71efb5d73
2 changed files with 27 additions and 6 deletions

View File

@@ -479,8 +479,16 @@ def freeze():
# 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 @@ def status(ignore_submodules=None):
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'
"""