Skip to content

Commit

Permalink
Prevent staged rename from displaying unstaged changes
Browse files Browse the repository at this point in the history
[ jf: added test cases and fixed to handle file names with length < 3 ]

Fixes #472
Closes #491
  • Loading branch information
harish authored and jonas committed Apr 13, 2016
1 parent 5fec140 commit 7174bec
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 32 additions & 0 deletions test/main/show-changes-after-rename-test
Original file line number Diff line number Diff line change
@@ -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' <<EOF
$YYY_MM_DD_HH_MM Unknown o Staged changes
2009-02-13 23:31 Committer I [master] commit1
[main] Staged changes 100%
EOF
24 changes: 24 additions & 0 deletions test/main/show-changes-test
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ steps '
:refresh
:save-display main-with-staged-and-unstaged.screen
:exec @git reset --hard
:exec @git mv b.c b1.c
:refresh
:save-display main-with-renamed.screen
:exec @git mv b1.c b.c
:exec @setup-conflict.sh
:refresh
:save-display main-with-conflict.screen
Expand Down Expand Up @@ -157,6 +163,24 @@ $YYY_MM_DD_HH_MM Unknown o Staged changes
[main] Unstaged changes 100%
EOF

assert_equals 'main-with-renamed.screen' <<EOF
$YYY_MM_DD_HH_MM Unknown o Staged changes
2009-02-13 23:31 A. U. Thor I [master] Initial commit
[main] Staged changes 100%
EOF

assert_equals 'main-with-conflict.screen' <<EOF
$YYY_MM_DD_HH_MM Unknown o Unstaged changes
2009-03-11 12:38 Committer o [conflict-master] Change: c'
Expand Down

0 comments on commit 7174bec

Please sign in to comment.