2022-08-12 20:10:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git diagnose'
|
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success UNZIP 'creates diagnostics zip archive' '
|
|
|
|
test_when_finished rm -rf report &&
|
|
|
|
|
|
|
|
git diagnose -o report -s test >out &&
|
|
|
|
grep "Available space" out &&
|
|
|
|
|
|
|
|
zip_path=report/git-diagnostics-test.zip &&
|
|
|
|
test_path_is_file "$zip_path" &&
|
|
|
|
|
|
|
|
# Check zipped archive content
|
|
|
|
"$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
|
|
|
|
test_file_not_empty out &&
|
|
|
|
|
|
|
|
"$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
|
|
|
|
grep ".git/objects" out &&
|
|
|
|
|
|
|
|
"$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
|
|
|
|
grep "^Total: [0-9][0-9]*" out &&
|
|
|
|
|
|
|
|
# Should not include .git directory contents by default
|
|
|
|
! "$GIT_UNZIP" -l "$zip_path" | grep ".git/"
|
2022-08-12 20:10:16 +00:00
|
|
|
'
|
|
|
|
|
diagnose.c: refactor to safely use 'd_type'
Refactor usage of the 'd_type' property of 'struct dirent' in 'diagnose.c'
to instead utilize the compatibility macro 'DTYPE()'. On systems where
'd_type' is not present in 'struct dirent', this macro will always return
'DT_UNKNOWN'. In that case, instead fall back on using the 'stat.st_mode' to
determine whether the dirent points to a dir, file, or link.
Additionally, add a test to 't0092-diagnose.sh' to verify that files (e.g.,
loose objects) are counted properly.
Note that the new function 'get_dtype()' is based on 'resolve_dtype()' in
'dir.c' (which itself was refactored from a prior 'get_dtype()' in
ad6f2157f9 (dir: restructure in a way to avoid passing around a struct
dirent, 2020-01-16)), but differs in that it is meant for use on arbitrary
files, such as those inside the '.git' dir. Because of this, it does not
search the index for a matching entry to derive the 'd_type'.
Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-17 18:16:55 +00:00
|
|
|
test_expect_success UNZIP 'counts loose objects' '
|
|
|
|
test_commit A &&
|
|
|
|
|
|
|
|
# After committing, should have non-zero loose objects
|
|
|
|
git diagnose -o test-count -s 1 >out &&
|
|
|
|
zip_path=test-count/git-diagnostics-1.zip &&
|
|
|
|
"$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
|
|
|
|
grep "^Total: [1-9][0-9]* loose objects" out
|
|
|
|
'
|
|
|
|
|
2022-08-12 20:10:16 +00:00
|
|
|
test_expect_success UNZIP '--mode=stats excludes .git dir contents' '
|
|
|
|
test_when_finished rm -rf report &&
|
|
|
|
|
|
|
|
git diagnose -o report -s test --mode=stats >out &&
|
|
|
|
|
|
|
|
# Includes pack quantity/size info
|
diagnose.c: refactor to safely use 'd_type'
Refactor usage of the 'd_type' property of 'struct dirent' in 'diagnose.c'
to instead utilize the compatibility macro 'DTYPE()'. On systems where
'd_type' is not present in 'struct dirent', this macro will always return
'DT_UNKNOWN'. In that case, instead fall back on using the 'stat.st_mode' to
determine whether the dirent points to a dir, file, or link.
Additionally, add a test to 't0092-diagnose.sh' to verify that files (e.g.,
loose objects) are counted properly.
Note that the new function 'get_dtype()' is based on 'resolve_dtype()' in
'dir.c' (which itself was refactored from a prior 'get_dtype()' in
ad6f2157f9 (dir: restructure in a way to avoid passing around a struct
dirent, 2020-01-16)), but differs in that it is meant for use on arbitrary
files, such as those inside the '.git' dir. Because of this, it does not
search the index for a matching entry to derive the 'd_type'.
Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-17 18:16:55 +00:00
|
|
|
zip_path=report/git-diagnostics-test.zip &&
|
2022-08-12 20:10:16 +00:00
|
|
|
"$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
|
|
|
|
grep ".git/objects" out &&
|
|
|
|
|
|
|
|
# Does not include .git directory contents
|
|
|
|
! "$GIT_UNZIP" -l "$zip_path" | grep ".git/"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success UNZIP '--mode=all includes .git dir contents' '
|
|
|
|
test_when_finished rm -rf report &&
|
|
|
|
|
|
|
|
git diagnose -o report -s test --mode=all >out &&
|
|
|
|
|
|
|
|
# Includes pack quantity/size info
|
diagnose.c: refactor to safely use 'd_type'
Refactor usage of the 'd_type' property of 'struct dirent' in 'diagnose.c'
to instead utilize the compatibility macro 'DTYPE()'. On systems where
'd_type' is not present in 'struct dirent', this macro will always return
'DT_UNKNOWN'. In that case, instead fall back on using the 'stat.st_mode' to
determine whether the dirent points to a dir, file, or link.
Additionally, add a test to 't0092-diagnose.sh' to verify that files (e.g.,
loose objects) are counted properly.
Note that the new function 'get_dtype()' is based on 'resolve_dtype()' in
'dir.c' (which itself was refactored from a prior 'get_dtype()' in
ad6f2157f9 (dir: restructure in a way to avoid passing around a struct
dirent, 2020-01-16)), but differs in that it is meant for use on arbitrary
files, such as those inside the '.git' dir. Because of this, it does not
search the index for a matching entry to derive the 'd_type'.
Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-17 18:16:55 +00:00
|
|
|
zip_path=report/git-diagnostics-test.zip &&
|
2022-08-12 20:10:16 +00:00
|
|
|
"$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
|
|
|
|
grep ".git/objects" out &&
|
|
|
|
|
|
|
|
# Includes .git directory contents
|
|
|
|
"$GIT_UNZIP" -l "$zip_path" | grep ".git/" &&
|
|
|
|
|
|
|
|
"$GIT_UNZIP" -p "$zip_path" .git/HEAD >out &&
|
|
|
|
test_file_not_empty out
|
2022-08-12 20:10:15 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|