Skip to content

Commit 9fa7ac2

Browse files
authored
Switch from diff-index to diff (#9)
`diff-index`: Compare the content and mode of the blobs found in a tree object with the corresponding tracked files in the working tree, or with the corresponding paths in the index. Unlike `diff`, which only compares the content. This has the implication (only on Linux) that if you were to recreate a file (or do something like change a file's timestamp with `touch`, as in the test) then a check with `diff-index` would drop us into that code path for there to subsequently be no known files which had changed. This behaviour came up when testing with Appraisal, which re-creates lockfiles when run, but the content is the same. https://stackoverflow.com/questions/24197606/whats-the-difference-between-git-diff-and-gif-diff-index https://github.com/thoughtbot/appraisal
1 parent f9da4c4 commit 9fa7ac2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

bin/diff-check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
if ! git diff-index --quiet HEAD; then
5+
if ! git diff --quiet HEAD; then
66
printf 'These files changed when running the command:\n\n'
77

88
git diff --name-only | while read -r n ; do

spec/black_box/diff-check_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,31 @@
3939
end
4040
end
4141

42+
context "with a non-content file change" do
43+
it "emits no output" do
44+
session = create_session
45+
46+
session.run("touch README")
47+
48+
expect(session.run("diff-check")).to have_no_stdout
49+
expect(session.run("diff-check")).to have_no_stderr
50+
end
51+
52+
it "exits with a status of 0" do
53+
session = create_session
54+
55+
session.run("touch README")
56+
57+
expect(session.run("diff-check")).to be_a_success
58+
end
59+
end
60+
4261
def create_session
4362
session = JetBlack::Session.new
4463

4564
session.run("git init")
4665
session.run("echo 'Hello world' >> README")
66+
session.run("touch -d '2 hours ago' README")
4767
session.run("git add .; git commit -m 'initial commit'")
4868

4969
session

0 commit comments

Comments
 (0)