mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'py/diff-submodule'
* py/diff-submodule: is_racy_timestamp(): do not check timestamp for gitlinks diff-lib.c: rename check_work_tree_entity() diff: a submodule not checked out is not modified Add t7506 to test submodule related functions for git-status t4027: test diff for submodule with empty directory
This commit is contained in:
commit
2855e70ad1
33
diff-lib.c
33
diff-lib.c
|
@ -337,11 +337,17 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
|
||||||
}
|
}
|
||||||
return run_diff_files(revs, options);
|
return run_diff_files(revs, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See if work tree has an entity that can be staged. Return 0 if so,
|
* Has the work tree entity been removed?
|
||||||
* return 1 if not and return -1 if error.
|
*
|
||||||
|
* Return 1 if it was removed from the work tree, 0 if an entity to be
|
||||||
|
* compared with the cache entry ce still exists (the latter includes
|
||||||
|
* the case where a directory that is not a submodule repository
|
||||||
|
* exists for ce that is a submodule -- it is a submodule that is not
|
||||||
|
* checked out). Return negative for an error.
|
||||||
*/
|
*/
|
||||||
static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
|
static int check_removed(const struct cache_entry *ce, struct stat *st, char *symcache)
|
||||||
{
|
{
|
||||||
if (lstat(ce->name, st) < 0) {
|
if (lstat(ce->name, st) < 0) {
|
||||||
if (errno != ENOENT && errno != ENOTDIR)
|
if (errno != ENOENT && errno != ENOTDIR)
|
||||||
|
@ -352,7 +358,20 @@ static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st,
|
||||||
return 1;
|
return 1;
|
||||||
if (S_ISDIR(st->st_mode)) {
|
if (S_ISDIR(st->st_mode)) {
|
||||||
unsigned char sub[20];
|
unsigned char sub[20];
|
||||||
if (resolve_gitlink_ref(ce->name, "HEAD", sub))
|
|
||||||
|
/*
|
||||||
|
* If ce is already a gitlink, we can have a plain
|
||||||
|
* directory (i.e. the submodule is not checked out),
|
||||||
|
* or a checked out submodule. Either case this is not
|
||||||
|
* a case where something was removed from the work tree,
|
||||||
|
* so we will return 0.
|
||||||
|
*
|
||||||
|
* Otherwise, if the directory is not a submodule
|
||||||
|
* repository, that means ce which was a blob turned into
|
||||||
|
* a directory --- the blob was removed!
|
||||||
|
*/
|
||||||
|
if (!S_ISGITLINK(ce->ce_mode) &&
|
||||||
|
resolve_gitlink_ref(ce->name, "HEAD", sub))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -402,7 +421,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
||||||
memset(&(dpath->parent[0]), 0,
|
memset(&(dpath->parent[0]), 0,
|
||||||
sizeof(struct combine_diff_parent)*5);
|
sizeof(struct combine_diff_parent)*5);
|
||||||
|
|
||||||
changed = check_work_tree_entity(ce, &st, symcache);
|
changed = check_removed(ce, &st, symcache);
|
||||||
if (!changed)
|
if (!changed)
|
||||||
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
|
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
|
||||||
else {
|
else {
|
||||||
|
@ -466,7 +485,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
||||||
if (ce_uptodate(ce))
|
if (ce_uptodate(ce))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
changed = check_work_tree_entity(ce, &st, symcache);
|
changed = check_removed(ce, &st, symcache);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
if (changed < 0) {
|
if (changed < 0) {
|
||||||
perror(ce->name);
|
perror(ce->name);
|
||||||
|
@ -527,7 +546,7 @@ static int get_stat_data(struct cache_entry *ce,
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
int changed;
|
int changed;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
changed = check_work_tree_entity(ce, &st, cbdata->symcache);
|
changed = check_removed(ce, &st, cbdata->symcache);
|
||||||
if (changed < 0)
|
if (changed < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else if (changed) {
|
else if (changed) {
|
||||||
|
|
|
@ -198,7 +198,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
|
||||||
|
|
||||||
static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
|
static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
|
||||||
{
|
{
|
||||||
return (istate->timestamp &&
|
return (!S_ISGITLINK(ce->ce_mode) &&
|
||||||
|
istate->timestamp &&
|
||||||
((unsigned int)istate->timestamp) <= ce->ce_mtime);
|
((unsigned int)istate->timestamp) <= ce->ce_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,4 +50,11 @@ test_expect_success 'git diff-files --raw' '
|
||||||
test_cmp expect actual.files
|
test_cmp expect actual.files
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git diff (empty submodule dir)' '
|
||||||
|
: >empty &&
|
||||||
|
rm -rf sub/* sub/.git &&
|
||||||
|
git diff > actual.empty &&
|
||||||
|
test_cmp empty actual.empty
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
38
t/t7506-status-submodule.sh
Executable file
38
t/t7506-status-submodule.sh
Executable file
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='git-status for submodule'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
test_create_repo sub
|
||||||
|
cd sub &&
|
||||||
|
: >bar &&
|
||||||
|
git add bar &&
|
||||||
|
git commit -m " Add bar" &&
|
||||||
|
cd .. &&
|
||||||
|
git add sub &&
|
||||||
|
git commit -m "Add submodule sub"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status clean' '
|
||||||
|
git status |
|
||||||
|
grep "nothing to commit"
|
||||||
|
'
|
||||||
|
test_expect_success 'status -a clean' '
|
||||||
|
git status -a |
|
||||||
|
grep "nothing to commit"
|
||||||
|
'
|
||||||
|
test_expect_success 'rm submodule contents' '
|
||||||
|
rm -rf sub/* sub/.git
|
||||||
|
'
|
||||||
|
test_expect_success 'status clean (empty submodule dir)' '
|
||||||
|
git status |
|
||||||
|
grep "nothing to commit"
|
||||||
|
'
|
||||||
|
test_expect_success 'status -a clean (empty submodule dir)' '
|
||||||
|
git status -a |
|
||||||
|
grep "nothing to commit"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in a new issue