Show submodules as modified when they contain a dirty work tree
v2 cover Show submodules as modified when they contain a dirty work tree
Here is the updated version of the two patches.
This fixes all issues raised and passes the test suite.
Jens Lehmann (1):
Show submodules as modified when they contain a dirty work tree
Junio C Hamano (1):
Teach diff that modified submodule directory is dirty
diff-lib.c | 8 +++- diff.c | 9 ++++- submodule.c | 49 +++++++++++++++++++++++++ submodule.h | 1 + t/t4027-diff-submodule.sh | 84 ++++++++++++++++++++++++++++++++++++++++++- t/t7506-status-submodule.sh | 83 ++++++++++++++++++++++++++++++++++-------- 6 files changed, 214 insertions(+), 20 deletions(-)
PATCH v2 1/2 Show submodules as modified when they contain a dirty work tree
Until now a submodule only then showed up as modified in the supermodule when the last commit in the submodule differed from the one in the index or the diffed against commit of the superproject. A dirty work tree containing new untracked or modified files in a submodule was undetectable when looking at it from the superproject.
Now git status and git diff (against the work tree) in the superproject will also display submodules as modified when they contain untracked or modified files, even if the compared ref matches the HEAD of the submodule.
---
Changed since the last version:
- Added missing include (spotted by Junio)
- Made test 7506 more robust (thanks to Nanako)
- When diffing the work tree against a commit in the supermodule the submodule did not show up as modified when the refs matched
diff-lib.c | 8 +++- submodule.c | 49 +++++++++++++++++++++++++ submodule.h | 1 + t/t7506-status-submodule.sh | 83 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 124 insertions(+), 17 deletions(-)
diff-lib.c +6 -2
@@ -10,6 +10,7 @@#include "cache-tree.h" #include "unpack-trees.h" #include "refs.h" +#include "submodule.h" /* * diff-files
@@ -159,7 +160,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)continue ; } -if (ce_uptodate (ce) ||ce_skip_worktree (ce)) +if ((ce_uptodate (ce) && !S_ISGITLINK (ce->ce_mode)) ||ce_skip_worktree (ce))continue ;/* If CE_VALID is set, don't look at workdir for file removal */
@@ -176,6 +177,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)continue ; } changed =ce_match_stat (ce, &st, ce_option); +if (S_ISGITLINK (ce->ce_mode) && !changed) + changed =is_submodule_modified (ce->name);if (!changed) {ce_mark_uptodate (ce);if (!DIFF_OPT_TST (&revs->diffopt,FIND_COPIES_HARDER ))
@@ -230,7 +233,8 @@ static int get_stat_data(struct cache_entry *ce,return -1 ; } changed =ce_match_stat (ce, &st,0 ); -if (changed) { +if (changed + || (S_ISGITLINK (ce->ce_mode) &&is_submodule_modified (ce->name))) { mode =ce_mode_from_stat (ce, st.st_mode); sha1 = null_sha1; }
submodule.c +49 -0
58 lines not on this page · raw message
submodule.h +1 -0
@@ -4,5 +4,6 @@void show_submodule_summary (FILE *f,const char *path,unsigned char one[20 ],unsigned char two[20 ],const char *del,const char *add,const char *reset); +int is_submodule_modified (const char *path);#endif
t/t7506-status-submodule.sh +68 -15
102 lines not on this page · raw message
Signature · 1 line
1.6.6.332.g1985b
PATCH v2 2/2 Teach diff that modified submodule directory is dirty
In reply to Jens LehmannFrom: Junio C Hamano <[email protected]>
A diff run in superproject only compares the name of the commit object bound at the submodule paths. When we compare with a work tree and the checked out submodule directory is dirty (e.g. has either staged or unstaged changes, or has new files the user forgot to add to the index), show the work tree side as "dirty".
---
Changed since the last version:
- I added 3 tests for "git diff HEAD" when refs match (the HEAD in the submodule is the same as last committed in the superproject)
diff.c | 9 ++++- t/t4027-diff-submodule.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 3 deletions(-)
diff.c +7 -2
@@ -2029,9 +2029,14 @@ static int populate_from_stdin(struct diff_filespec *s)static int diff_populate_gitlink (struct diff_filespec *s,int size_only) {int len; -char *data =xmalloc (100 ); +char *data =xmalloc (100 ), *dirty ="" ; + +/* Are we looking at the work tree? */ +if (!s->sha1_valid &&is_submodule_modified (s->path)) + dirty ="-dirty" ; + len =snprintf (data,100 , -"Subproject commit %s\n" ,sha1_to_hex (s->sha1)); +"Subproject commit %s%s\n" ,sha1_to_hex (s->sha1), dirty); s->data = data; s->size = len; s->should_free =1 ;
t/t4027-diff-submodule.sh +83 -1
96 lines not on this page · raw message
Signature · 1 line
1.6.6.332.g1985b