t / t3303-notes-subtrees.shon commit Merge branch 'ss/fix-config-fd-leak' into maint (8136099)
   1#!/bin/sh
   2
   3test_description='Test commit notes organized in subtrees'
   4
   5. ./test-lib.sh
   6
   7number_of_commits=100
   8
   9start_note_commit () {
  10        test_tick &&
  11        cat <<INPUT_END
  12commit refs/notes/commits
  13committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  14data <<COMMIT
  15notes
  16COMMIT
  17
  18from refs/notes/commits^0
  19deleteall
  20INPUT_END
  21
  22}
  23
  24verify_notes () {
  25        git log | grep "^    " > output &&
  26        i=$number_of_commits &&
  27        while [ $i -gt 0 ]; do
  28                echo "    commit #$i" &&
  29                echo "    note for commit #$i" &&
  30                i=$(($i-1));
  31        done > expect &&
  32        test_cmp expect output
  33}
  34
  35test_expect_success "setup: create $number_of_commits commits" '
  36
  37        (
  38                nr=0 &&
  39                while [ $nr -lt $number_of_commits ]; do
  40                        nr=$(($nr+1)) &&
  41                        test_tick &&
  42                        cat <<INPUT_END
  43commit refs/heads/master
  44committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  45data <<COMMIT
  46commit #$nr
  47COMMIT
  48
  49M 644 inline file
  50data <<EOF
  51file in commit #$nr
  52EOF
  53
  54INPUT_END
  55
  56                done &&
  57                test_tick &&
  58                cat <<INPUT_END
  59commit refs/notes/commits
  60committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  61data <<COMMIT
  62no notes
  63COMMIT
  64
  65deleteall
  66
  67INPUT_END
  68
  69        ) |
  70        git fast-import --quiet &&
  71        git config core.notesRef refs/notes/commits
  72'
  73
  74test_sha1_based () {
  75        (
  76                start_note_commit &&
  77                nr=$number_of_commits &&
  78                git rev-list refs/heads/master |
  79                while read sha1; do
  80                        note_path=$(echo "$sha1" | sed "$1")
  81                        cat <<INPUT_END &&
  82M 100644 inline $note_path
  83data <<EOF
  84note for commit #$nr
  85EOF
  86
  87INPUT_END
  88
  89                        nr=$(($nr-1))
  90                done
  91        ) |
  92        git fast-import --quiet
  93}
  94
  95test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
  96test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
  97
  98test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
  99test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
 100
 101test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
 102test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
 103
 104test_same_notes () {
 105        (
 106                start_note_commit &&
 107                nr=$number_of_commits &&
 108                git rev-list refs/heads/master |
 109                while read sha1; do
 110                        first_note_path=$(echo "$sha1" | sed "$1")
 111                        second_note_path=$(echo "$sha1" | sed "$2")
 112                        cat <<INPUT_END &&
 113M 100644 inline $second_note_path
 114data <<EOF
 115note for commit #$nr
 116EOF
 117
 118M 100644 inline $first_note_path
 119data <<EOF
 120note for commit #$nr
 121EOF
 122
 123INPUT_END
 124
 125                        nr=$(($nr-1))
 126                done
 127        ) |
 128        git fast-import --quiet
 129}
 130
 131test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
 132test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
 133
 134test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
 135test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
 136
 137test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
 138test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
 139
 140test_expect_success 'test same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
 141test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
 142
 143test_concatenated_notes () {
 144        (
 145                start_note_commit &&
 146                nr=$number_of_commits &&
 147                git rev-list refs/heads/master |
 148                while read sha1; do
 149                        first_note_path=$(echo "$sha1" | sed "$1")
 150                        second_note_path=$(echo "$sha1" | sed "$2")
 151                        cat <<INPUT_END &&
 152M 100644 inline $second_note_path
 153data <<EOF
 154second note for commit #$nr
 155EOF
 156
 157M 100644 inline $first_note_path
 158data <<EOF
 159first note for commit #$nr
 160EOF
 161
 162INPUT_END
 163
 164                        nr=$(($nr-1))
 165                done
 166        ) |
 167        git fast-import --quiet
 168}
 169
 170verify_concatenated_notes () {
 171        git log | grep "^    " > output &&
 172        i=$number_of_commits &&
 173        while [ $i -gt 0 ]; do
 174                echo "    commit #$i" &&
 175                echo "    first note for commit #$i" &&
 176                echo "    " &&
 177                echo "    second note for commit #$i" &&
 178                i=$(($i-1));
 179        done > expect &&
 180        test_cmp expect output
 181}
 182
 183test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
 184test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
 185
 186test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
 187test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
 188
 189test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
 190test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
 191
 192test_expect_success 'test notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|" "s|^\(..\)\(..\)|\1/\2/|"'
 193test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
 194
 195test_done