contrib / mw-to-git / t / t9360-mw-to-git-clone.shon commit Merge branch 'vd/doc-unpack-objects' (ea06592)
   1#!/bin/sh
   2#
   3# Copyright (C) 2012
   4#     Charles Roussel <charles.roussel@ensimag.imag.fr>
   5#     Simon Cathebras <simon.cathebras@ensimag.imag.fr>
   6#     Julien Khayat <julien.khayat@ensimag.imag.fr>
   7#     Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
   8#     Simon Perrat <simon.perrat@ensimag.imag.fr>
   9#
  10# License: GPL v2 or later
  11
  12
  13test_description='Test the Git Mediawiki remote helper: git clone'
  14
  15. ./test-gitmw-lib.sh
  16. $TEST_DIRECTORY/test-lib.sh
  17
  18
  19test_check_precond
  20
  21
  22test_expect_success 'Git clone creates the expected git log with one file' '
  23        wiki_reset &&
  24        wiki_editpage foo "this is not important" false -c cat -s "this must be the same" &&
  25        git clone mediawiki::'"$WIKI_URL"' mw_dir_1 &&
  26        (
  27                cd mw_dir_1 &&
  28                git log --format=%s HEAD^..HEAD >log.tmp
  29        ) &&
  30        echo "this must be the same" >msg.tmp &&
  31        diff -b mw_dir_1/log.tmp msg.tmp
  32'
  33
  34
  35test_expect_success 'Git clone creates the expected git log with multiple files' '
  36        wiki_reset &&
  37        wiki_editpage daddy "this is not important" false -s="this must be the same" &&
  38        wiki_editpage daddy "neither is this" true -s="this must also be the same" &&
  39        wiki_editpage daddy "neither is this" true -s="same same same" &&
  40        wiki_editpage dj "dont care" false -s="identical" &&
  41        wiki_editpage dj "dont care either" true -s="identical too" &&
  42        git clone mediawiki::'"$WIKI_URL"' mw_dir_2 &&
  43        (
  44                cd mw_dir_2 &&
  45                git log --format=%s Daddy.mw  >logDaddy.tmp &&
  46                git log --format=%s Dj.mw >logDj.tmp
  47        ) &&
  48        echo "same same same" >msgDaddy.tmp &&
  49        echo "this must also be the same" >>msgDaddy.tmp &&
  50        echo "this must be the same" >>msgDaddy.tmp &&
  51        echo "identical too" >msgDj.tmp &&
  52        echo "identical" >>msgDj.tmp &&
  53        diff -b mw_dir_2/logDaddy.tmp msgDaddy.tmp &&
  54        diff -b mw_dir_2/logDj.tmp msgDj.tmp
  55'
  56
  57
  58test_expect_success 'Git clone creates only Main_Page.mw with an empty wiki' '
  59        wiki_reset &&
  60        git clone mediawiki::'"$WIKI_URL"' mw_dir_3 &&
  61        test_contains_N_files mw_dir_3 1 &&
  62        test_path_is_file mw_dir_3/Main_Page.mw
  63'
  64
  65test_expect_success 'Git clone does not fetch a deleted page' '
  66        wiki_reset &&
  67        wiki_editpage foo "this page must be deleted before the clone" false &&
  68        wiki_delete_page foo &&
  69        git clone mediawiki::'"$WIKI_URL"' mw_dir_4 &&
  70        test_contains_N_files mw_dir_4 1 &&
  71        test_path_is_file mw_dir_4/Main_Page.mw &&
  72        test_path_is_missing mw_dir_4/Foo.mw
  73'
  74
  75test_expect_success 'Git clone works with page added' '
  76        wiki_reset &&
  77        wiki_editpage foo " I will be cloned" false &&
  78        wiki_editpage bar "I will be cloned" false &&
  79        git clone mediawiki::'"$WIKI_URL"' mw_dir_5 &&
  80        wiki_getallpage ref_page_5 &&
  81        test_diff_directories mw_dir_5 ref_page_5 &&
  82        wiki_delete_page foo &&
  83        wiki_delete_page bar
  84'
  85
  86test_expect_success 'Git clone works with an edited page ' '
  87        wiki_reset &&
  88        wiki_editpage foo "this page will be edited" \
  89                false -s "first edition of page foo"&&
  90        wiki_editpage foo "this page has been edited and must be on the clone " true &&
  91        git clone mediawiki::'"$WIKI_URL"' mw_dir_6 &&
  92        test_path_is_file mw_dir_6/Foo.mw &&
  93        test_path_is_file mw_dir_6/Main_Page.mw &&
  94        wiki_getallpage mw_dir_6/page_ref_6 &&
  95        test_diff_directories mw_dir_6 mw_dir_6/page_ref_6 &&
  96        (
  97                cd mw_dir_6 &&
  98                git log --format=%s HEAD^ Foo.mw > ../Foo.log
  99        ) &&
 100        echo "first edition of page foo" > FooExpect.log &&
 101        diff FooExpect.log Foo.log
 102'
 103
 104
 105test_expect_success 'Git clone works with several pages and some deleted ' '
 106        wiki_reset &&
 107        wiki_editpage foo "this page will not be deleted" false &&
 108        wiki_editpage bar "I must not be erased" false &&
 109        wiki_editpage namnam "I will not be there at the end" false &&
 110        wiki_editpage nyancat "nyan nyan nyan delete me" false &&
 111        wiki_delete_page namnam &&
 112        wiki_delete_page nyancat &&
 113        git clone mediawiki::'"$WIKI_URL"' mw_dir_7 &&
 114        test_path_is_file mw_dir_7/Foo.mw &&
 115        test_path_is_file mw_dir_7/Bar.mw &&
 116        test_path_is_missing mw_dir_7/Namnam.mw &&
 117        test_path_is_missing mw_dir_7/Nyancat.mw &&
 118        wiki_getallpage mw_dir_7/page_ref_7 &&
 119        test_diff_directories mw_dir_7 mw_dir_7/page_ref_7
 120'
 121
 122
 123test_expect_success 'Git clone works with one specific page cloned ' '
 124        wiki_reset &&
 125        wiki_editpage foo "I will not be cloned" false &&
 126        wiki_editpage bar "Do not clone me" false &&
 127        wiki_editpage namnam "I will be cloned :)" false  -s="this log must stay" &&
 128        wiki_editpage nyancat "nyan nyan nyan you cant clone me" false &&
 129        git clone -c remote.origin.pages=namnam \
 130                mediawiki::'"$WIKI_URL"' mw_dir_8 &&
 131        test_contains_N_files mw_dir_8 1 &&
 132        test_path_is_file mw_dir_8/Namnam.mw &&
 133        test_path_is_missing mw_dir_8/Main_Page.mw &&
 134        (
 135                cd mw_dir_8 &&
 136                echo "this log must stay" >msg.tmp &&
 137                git log --format=%s >log.tmp &&
 138                diff -b msg.tmp log.tmp
 139        ) &&
 140        wiki_check_content mw_dir_8/Namnam.mw Namnam
 141'
 142
 143test_expect_success 'Git clone works with multiple specific page cloned ' '
 144        wiki_reset &&
 145        wiki_editpage foo "I will be there" false &&
 146        wiki_editpage bar "I will not disapear" false &&
 147        wiki_editpage namnam "I be erased" false &&
 148        wiki_editpage nyancat "nyan nyan nyan you will not erase me" false &&
 149        wiki_delete_page namnam &&
 150        git clone -c remote.origin.pages="foo bar nyancat namnam" \
 151                mediawiki::'"$WIKI_URL"' mw_dir_9 &&
 152        test_contains_N_files mw_dir_9 3 &&
 153        test_path_is_missing mw_dir_9/Namnam.mw &&
 154        test_path_is_file mw_dir_9/Foo.mw &&
 155        test_path_is_file mw_dir_9/Nyancat.mw &&
 156        test_path_is_file mw_dir_9/Bar.mw &&
 157        wiki_check_content mw_dir_9/Foo.mw Foo &&
 158        wiki_check_content mw_dir_9/Bar.mw Bar &&
 159        wiki_check_content mw_dir_9/Nyancat.mw Nyancat
 160'
 161
 162test_expect_success 'Mediawiki-clone of several specific pages on wiki' '
 163        wiki_reset &&
 164        wiki_editpage foo "foo 1" false &&
 165        wiki_editpage bar "bar 1" false &&
 166        wiki_editpage dummy "dummy 1" false &&
 167        wiki_editpage cloned_1 "cloned_1 1" false &&
 168        wiki_editpage cloned_2 "cloned_2 2" false &&
 169        wiki_editpage cloned_3 "cloned_3 3" false &&
 170        mkdir -p ref_page_10 &&
 171        wiki_getpage cloned_1 ref_page_10 &&
 172        wiki_getpage cloned_2 ref_page_10 &&
 173        wiki_getpage cloned_3 ref_page_10 &&
 174        git clone -c remote.origin.pages="cloned_1 cloned_2 cloned_3" \
 175                mediawiki::'"$WIKI_URL"' mw_dir_10 &&
 176        test_diff_directories mw_dir_10 ref_page_10
 177'
 178
 179test_expect_success 'Git clone works with the shallow option' '
 180        wiki_reset &&
 181        wiki_editpage foo "1st revision, should be cloned" false &&
 182        wiki_editpage bar "1st revision, should be cloned" false &&
 183        wiki_editpage nyan "1st revision, should not be cloned" false &&
 184        wiki_editpage nyan "2nd revision, should be cloned" false &&
 185        git -c remote.origin.shallow=true clone \
 186                mediawiki::'"$WIKI_URL"' mw_dir_11 &&
 187        test_contains_N_files mw_dir_11 4 &&
 188        test_path_is_file mw_dir_11/Nyan.mw &&
 189        test_path_is_file mw_dir_11/Foo.mw &&
 190        test_path_is_file mw_dir_11/Bar.mw &&
 191        test_path_is_file mw_dir_11/Main_Page.mw &&
 192        (
 193                cd mw_dir_11 &&
 194                test `git log --oneline Nyan.mw | wc -l` -eq 1 &&
 195                test `git log --oneline Foo.mw | wc -l` -eq 1 &&
 196                test `git log --oneline Bar.mw | wc -l` -eq 1 &&
 197                test `git log --oneline Main_Page.mw | wc -l ` -eq 1
 198        ) &&
 199        wiki_check_content mw_dir_11/Nyan.mw Nyan &&
 200        wiki_check_content mw_dir_11/Foo.mw Foo &&
 201        wiki_check_content mw_dir_11/Bar.mw Bar &&
 202        wiki_check_content mw_dir_11/Main_Page.mw Main_Page
 203'
 204
 205test_expect_success 'Git clone works with the shallow option with a delete page' '
 206        wiki_reset &&
 207        wiki_editpage foo "1st revision, will be deleted" false &&
 208        wiki_editpage bar "1st revision, should be cloned" false &&
 209        wiki_editpage nyan "1st revision, should not be cloned" false &&
 210        wiki_editpage nyan "2nd revision, should be cloned" false &&
 211        wiki_delete_page foo &&
 212        git -c remote.origin.shallow=true clone \
 213                mediawiki::'"$WIKI_URL"' mw_dir_12 &&
 214        test_contains_N_files mw_dir_12 3 &&
 215        test_path_is_file mw_dir_12/Nyan.mw &&
 216        test_path_is_missing mw_dir_12/Foo.mw &&
 217        test_path_is_file mw_dir_12/Bar.mw &&
 218        test_path_is_file mw_dir_12/Main_Page.mw &&
 219        (
 220                cd mw_dir_12 &&
 221                test `git log --oneline Nyan.mw | wc -l` -eq 1 &&
 222                test `git log --oneline Bar.mw | wc -l` -eq 1 &&
 223                test `git log --oneline Main_Page.mw | wc -l ` -eq 1
 224        ) &&
 225        wiki_check_content mw_dir_12/Nyan.mw Nyan &&
 226        wiki_check_content mw_dir_12/Bar.mw Bar &&
 227        wiki_check_content mw_dir_12/Main_Page.mw Main_Page
 228'
 229
 230test_expect_success 'Test of fetching a category' '
 231        wiki_reset &&
 232        wiki_editpage Foo "I will be cloned" false -c=Category &&
 233        wiki_editpage Bar "Meet me on the repository" false -c=Category &&
 234        wiki_editpage Dummy "I will not come" false &&
 235        wiki_editpage BarWrong "I will stay online only" false -c=NotCategory &&
 236        git clone -c remote.origin.categories="Category" \
 237                mediawiki::'"$WIKI_URL"' mw_dir_13 &&
 238        wiki_getallpage ref_page_13 Category &&
 239        test_diff_directories mw_dir_13 ref_page_13
 240'
 241
 242test_expect_success 'Test of resistance to modification of category on wiki for clone' '
 243        wiki_reset &&
 244        wiki_editpage Tobedeleted "this page will be deleted" false -c=Catone &&
 245        wiki_editpage Tobeedited "this page will be modified" false -c=Catone &&
 246        wiki_editpage Normalone "this page wont be modified and will be on git" false -c=Catone &&
 247        wiki_editpage Notconsidered "this page will not appear on local" false &&
 248        wiki_editpage Othercategory "this page will not appear on local" false -c=Cattwo &&
 249        wiki_editpage Tobeedited "this page have been modified" true -c=Catone &&
 250        wiki_delete_page Tobedeleted
 251        git clone -c remote.origin.categories="Catone" \
 252                mediawiki::'"$WIKI_URL"' mw_dir_14 &&
 253        wiki_getallpage ref_page_14 Catone &&
 254        test_diff_directories mw_dir_14 ref_page_14
 255'
 256
 257test_done