Follow upstream changes -- rest
[git-darcs-import.git] / tests / optimize_relink.sh
blob40541ba13409891e7aff9197787fd6014dc3b648
2 #!/usr/bin/env bash
4 # For issue600, testing optimize --relink
6 set -ev
8 ## We don't support hard links on Windows.
10 if echo $OS | grep -i windows; then
11 echo darcs does not support hard links on Windows
12 exit 0
15 ## compare succeeds if there are hard links
16 compare () {
17 echo 'use File::Basename; $res=0; while ($fn=<'$1'/*>) { $fn2="'$2'/" . basename($fn); @fd1=lstat($fn); @fd2=lstat($fn2); $res += ($fd1[1] != $fd2[1]);}; exit($res);' | perl
20 rm -rf temp
21 mkdir temp
22 cd temp
24 mkdir x
25 darcs init --repodir x
26 cd x
27 date > foo
28 darcs add foo
29 darcs record -a -A me -m 'addfoo'
30 cd ..
32 ## Does the filesystem support hard linking at all?
33 mkdir z1
34 echo "hi" > z1/foo
35 mkdir z2
36 if ! ln z1/foo z2/foo ; then
37 echo No ln command for `pwd`; assuming no hard links.
38 exit 0
40 if ! compare z1 z2 ; then
41 echo Filesystem for `pwd` does not support hard links.
42 exit 0
44 # workaround for SunOS cp which does not support `-a' option but also
45 # doesn't fail when it is encountered.
46 cp -r x y
48 ## Now try relinking using darcs.
49 rm -rf z
50 darcs optimize --verbose --relink --repodir x --sibling y
51 rm -rf x/_darcs/patches/pend* y/_darcs/patches/pend*
52 if compare x/_darcs/patches y/_darcs/patches
53 then echo darcs --relink is working, hard links were done.
54 else echo darcs --relink is not working, it did not make any hard links.
55 exit 2
58 cd ..
59 rm -rf temp