From ca66756b4a6db44d87296263c75802619496d1ce Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 1 Dec 2007 23:00:00 +0000 Subject: [PATCH] Check for disappeared newborn files in git.tree_status (bug #8516) Organization: Straylight/Edgeware From: Catalin Marinas If a file is added to the index (stg add) but is removed from the shell, git.tree_status doesn't detect it but other commands like push fail. The patch adds a call to 'git diff-files' in git.tree_status. Signed-off-by: Catalin Marinas --- stgit/git.py | 16 ++++++++++++++-- t/t0002-status.sh | 12 ++++++++++++ t/t1202-push-undo.sh | 9 +++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/stgit/git.py b/stgit/git.py index b5551de..6744be0 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -230,15 +230,27 @@ def tree_status(files = None, tree_id = 'HEAD', unknown = False, conflicts = [] cache_files += [('C', filename) for filename in conflicts if not files or filename in files] + reported_files = set(conflicts) - # the rest + # files in the index args = diff_flags + [tree_id] if files: args += ['--'] + files for line in GRun('diff-index', *args).output_lines(): fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) - if fs[1] not in conflicts: + if fs[1] not in reported_files: cache_files.append(fs) + reported_files.add(fs[1]) + + # files in the index but changed on (or removed from) disk + args = list(diff_flags) + if files: + args += ['--'] + files + for line in GRun('diff-files', *args).output_lines(): + fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1)) + if fs[1] not in reported_files: + cache_files.append(fs) + reported_files.add(fs[1]) if verbose: out.done() diff --git a/t/t0002-status.sh b/t/t0002-status.sh index 6389a23..43e1ca0 100755 --- a/t/t0002-status.sh +++ b/t/t0002-status.sh @@ -159,4 +159,16 @@ test_expect_success 'Status after deleting a file' ' diff -u expected.txt output.txt ' +cat > expected.txt < output.txt && + diff -u expected.txt output.txt +' + test_done diff --git a/t/t1202-push-undo.sh b/t/t1202-push-undo.sh index 51ae138..edfa710 100755 --- a/t/t1202-push-undo.sh +++ b/t/t1202-push-undo.sh @@ -58,4 +58,13 @@ test_expect_success \ ! stg push bar ' +test_expect_success \ + 'Undo with disappeared newborn' \ + ' + touch newfile && + stg add newfile && + rm newfile && + stg push --undo + ' + test_done -- [mdw]