From 7174becb532da064212615a5feddd07e0d26295d Mon Sep 17 00:00:00 2001 From: Harish Lall Date: Wed, 6 Apr 2016 00:29:52 -0400 Subject: [PATCH] Prevent staged rename from displaying unstaged changes [ jf: added test cases and fixed to handle file names with length < 3 ] Fixes #472 Closes #491 --- NEWS.adoc | 1 + src/repo.c | 5 ++++ test/main/show-changes-after-rename-test | 32 ++++++++++++++++++++++++ test/main/show-changes-test | 24 ++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100755 test/main/show-changes-after-rename-test diff --git a/NEWS.adoc b/NEWS.adoc index 5d2568435..10d064ed8 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -33,6 +33,7 @@ Improvements: Bug fixes: + - Prevent staged rename from displaying unstaged changes (GH #472, #491) - Fix corrupt chunk header during staging of single lines. (GH #410) - Fix out of bounds read in graph-v2 module. (GH #402) - Add currently checked out branch to `%(branch)`. (GH #416) diff --git a/src/repo.c b/src/repo.c index fabea294f..882592da5 100644 --- a/src/repo.c +++ b/src/repo.c @@ -155,6 +155,11 @@ index_diff(struct index_diff *diff, bool untracked, bool count_all) if (!count_all && diff->staged && diff->unstaged && (!untracked || diff->untracked)) break; + + /* Skip source filename in rename */ + if (buf.data[0] == 'R') { + io_get(&io, &buf, 0, true); + } } if (io_error(&io)) diff --git a/test/main/show-changes-after-rename-test b/test/main/show-changes-after-rename-test new file mode 100755 index 000000000..c9f48d9bb --- /dev/null +++ b/test/main/show-changes-after-rename-test @@ -0,0 +1,32 @@ +#!/bin/sh +# +# Test case from https://github.com/jonas/tig/issues/472 + +. libtest.sh +. libgit.sh +. "$source_dir/util.sh" + +export LINES=4 + +steps ' + :save-display default.screen +' + +git_init + +test_setup_work_dir() { + echo data >file1 + git add file1 + git_commit -m "commit1" + echo data >file2 + git add file2 + git rm file1 +} + +test_tig + +assert_equals 'default.screen' <