@matheusbsbs / matheus-bagliano / commits / 721ceec1ad
Fork 0

Teach diff --submodule that modified submodule directory is dirty

Since commit 8e08b4 git diff does append "-dirty" to the work tree side if the working directory of a submodule contains new or modified files. Lets do the same when the --submodule option is used. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Jan 24, 2010 at 15:09 UTC 721ceec1ad12625e90b395fd0be0fae9049ebc22
4 files changed +72 -1
diff.c
+1 -1
@@ -1615,7 +1615,7 @@ static void builtin_diff(const char *name_a,
1615 const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
1616 const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
1617 show_submodule_summary(o->file, one ? one->path : two->path,
1618 - one->sha1, two->sha1,
1618 + one->sha1, two->sha1, two->dirty_submodule,
1619 del, add, reset);
1620 return;
1621 }
submodule.c
+3
@@ -36,6 +36,7 @@ static int add_submodule_odb(const char *path)
36
37 void show_submodule_summary(FILE *f, const char *path,
38 unsigned char one[20], unsigned char two[20],
39 + unsigned dirty_submodule,
40 const char *del, const char *add, const char *reset)
41 {
42 struct rev_info rev;
@@ -85,6 +86,8 @@ void show_submodule_summary(FILE *f, const char *path,
86 if (!fast_backward && !fast_forward)
87 strbuf_addch(&sb, '.');
88 strbuf_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV));
89 + if (dirty_submodule)
90 + strbuf_add(&sb, "-dirty", 6);
91 if (message)
92 strbuf_addf(&sb, " %s\n", message);
93 else
submodule.h
+1
@@ -3,6 +3,7 @@
3
4 void show_submodule_summary(FILE *f, const char *path,
5 unsigned char one[20], unsigned char two[20],
6 + unsigned dirty_submodule,
7 const char *del, const char *add, const char *reset);
8 int is_submodule_modified(const char *path);
9
t/t4041-diff-submodule.sh
+67
@@ -191,6 +191,73 @@ EOF
191 "
192
193 commit_file sm1 &&
194 +test_expect_success 'submodule is up to date' "
195 + git diff-index -p --submodule=log HEAD >actual &&
196 + diff actual - <<-EOF
197 +EOF
198 +"
199 +
200 +test_expect_success 'submodule contains untracked content' "
201 + echo new > sm1/new-file &&
202 + git diff-index -p --submodule=log HEAD >actual &&
203 + diff actual - <<-EOF
204 +Submodule sm1 $head6..$head6-dirty:
205 +EOF
206 +"
207 +
208 +test_expect_success 'submodule contains untracked and modifed content' "
209 + echo new > sm1/foo6 &&
210 + git diff-index -p --submodule=log HEAD >actual &&
211 + diff actual - <<-EOF
212 +Submodule sm1 $head6..$head6-dirty:
213 +EOF
214 +"
215 +
216 +test_expect_success 'submodule contains modifed content' "
217 + rm -f sm1/new-file &&
218 + git diff-index -p --submodule=log HEAD >actual &&
219 + diff actual - <<-EOF
220 +Submodule sm1 $head6..$head6-dirty:
221 +EOF
222 +"
223 +
224 +(cd sm1; git commit -mchange foo6 >/dev/null) &&
225 +head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
226 +test_expect_success 'submodule is modified' "
227 + git diff-index -p --submodule=log HEAD >actual &&
228 + diff actual - <<-EOF
229 +Submodule sm1 $head6..$head8:
230 + > change
231 +EOF
232 +"
233 +
234 +test_expect_success 'modified submodule contains untracked content' "
235 + echo new > sm1/new-file &&
236 + git diff-index -p --submodule=log HEAD >actual &&
237 + diff actual - <<-EOF
238 +Submodule sm1 $head6..$head8-dirty:
239 + > change
240 +EOF
241 +"
242 +
243 +test_expect_success 'modified submodule contains untracked and modifed content' "
244 + echo modification >> sm1/foo6 &&
245 + git diff-index -p --submodule=log HEAD >actual &&
246 + diff actual - <<-EOF
247 +Submodule sm1 $head6..$head8-dirty:
248 + > change
249 +EOF
250 +"
251 +
252 +test_expect_success 'modified submodule contains modifed content' "
253 + rm -f sm1/new-file &&
254 + git diff-index -p --submodule=log HEAD >actual &&
255 + diff actual - <<-EOF
256 +Submodule sm1 $head6..$head8-dirty:
257 + > change
258 +EOF
259 +"
260 +
261 rm -rf sm1
262 test_expect_success 'deleted submodule' "
263 git diff-index -p --submodule=log HEAD >actual &&