Raw
1 #!/bin/sh
2
3 test_description='basic tests of rev-list --disk-usage'
4
5 . ./test-lib.sh
6
7 # we want a mix of reachable and unreachable, as well as
8 # objects in the bitmapped pack and some outside of it
9 test_expect_success 'set up repository' '
10 test_commit --no-tag one &&
11 test_commit --no-tag two &&
12 git repack -adb &&
13 git reset --hard HEAD^ &&
14 test_commit --no-tag three &&
15 test_commit --no-tag four &&
16 git reset --hard HEAD^
17 '
18
19 # We don't want to hardcode sizes, because they depend on the exact details of
20 # packing, zlib, etc. We'll assume that the regular rev-list and cat-file
21 # machinery works and compare the --disk-usage output to that.
22 disk_usage_slow () {
23 git rev-list --no-object-names "$@" |
24 git cat-file --batch-check="%(objectsize:disk)" |
25 awk '{ i += $1 } END { print i }'
26 }
27
28 # check behavior with given rev-list options; note that
29 # whitespace is not preserved in args
30 check_du () {
31 args=$*
32
33 test_expect_success "generate expected size ($args)" "
34 disk_usage_slow $args >expect
35 "
36
37 test_expect_success "rev-list --disk-usage without bitmaps ($args)" "
38 git rev-list --disk-usage $args >actual &&
39 test_cmp expect actual
40 "
41
42 test_expect_success "rev-list --disk-usage with bitmaps ($args)" "
43 git rev-list --disk-usage --use-bitmap-index $args >actual &&
44 test_cmp expect actual
45 "
46 }
47
48 check_du HEAD
49 check_du --objects HEAD
50 check_du --objects HEAD^..HEAD
51
52 test_expect_success 'setup for --unpacked tests' '
53 git repack -adb &&
54 test_commit unpacked
55 '
56
57 check_du --all --objects --unpacked
58
59 # As mentioned above, don't use hardcode sizes as actual size, but use the
60 # output from git cat-file.
61 test_expect_success 'rev-list --disk-usage=human' '
62 git rev-list --objects HEAD --disk-usage=human >actual &&
63 disk_usage_slow --objects HEAD >actual_size &&
64 test_grep "$(cat actual_size) bytes" actual
65 '
66
67 test_expect_success 'rev-list --disk-usage=human with bitmaps' '
68 git rev-list --objects HEAD --use-bitmap-index --disk-usage=human >actual &&
69 disk_usage_slow --objects HEAD >actual_size &&
70 test_grep "$(cat actual_size) bytes" actual
71 '
72
73 test_expect_success 'rev-list use --disk-usage unproperly' '
74 test_must_fail git rev-list --objects HEAD --disk-usage=typo 2>err &&
75 cat >expect <<-\EOF &&
76 fatal: invalid value for '\''--disk-usage=<format>'\'': '\''typo'\'', the only allowed format is '\''human'\''
77 EOF
78 test_cmp err expect
79 '
80
81 test_done