File: t-dedup.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (107 lines) | stat: -rwxr-xr-x 2,997 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash

. "$(dirname "$0")/testlib.sh"

begin_test "dedup"
(
  set -e

  reponame="dedup"
  git init $reponame
  cd $reponame

  # Confirm Git LFS extensions prevent de-duplication
  git config lfs.extension.foo.clean "foo-clean %f"
  git config lfs.extension.foo.smudge "foo-smudge %f"
  git config lfs.extension.foo.priority 0

  result=$(git lfs dedup 2>&1) && true
  if ( echo $result | grep "This system does not support de-duplication." ); then
    exit
  fi
  echo "$result" | grep 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.'

  git config --unset lfs.extension.foo.clean
  git config --unset lfs.extension.foo.smudge
  git config --unset lfs.extension.foo.priority

  # Create a commit with some files tracked by git-lfs
  git lfs track *.dat
  echo "test data" > a.dat
  echo "test data 2" > b.dat
  git add .gitattributes *.dat
  git commit -m "first commit"

  # Delete file b and lock directory
  bOid=$(git log --patch b.dat | grep "^+oid" | cut -d ":" -f 2)
  bOid12=$(echo $bOid | cut -b 1-2)
  bOid34=$(echo $bOid | cut -b 3-4)
  rm ".git/lfs/objects/$bOid12/$bOid34/$bOid"

  # DO
  result=$(git lfs dedup 2>&1) && true

  # VERIFY: Expected
  #  Success: a.dat
  #  Success: b.dat
  echo "$result" | grep 'Success: a.dat'
  echo "$result" | grep -E 'Success:\s+b.dat|Skipped:\s+b.dat'
  # Sometimes mediafile of b.bat is restored by timing issue?
)
end_test

begin_test "dedup test"
(
  set -e

  reponame="dedup_test"
  git init $reponame
  cd $reponame

  # Confirm Git LFS extensions prevent de-duplication
  git config lfs.extension.foo.clean "foo-clean %f"
  git config lfs.extension.foo.smudge "foo-smudge %f"
  git config lfs.extension.foo.priority 0

  result=$(git lfs dedup --test 2>&1) && true
  if ( echo $result | grep "This system does not support de-duplication." ); then
    exit
  fi
  echo "$result" | grep 'This platform supports file de-duplication, however, Git LFS extensions are configured and therefore de-duplication can not be used.'

  git config --unset lfs.extension.foo.clean
  git config --unset lfs.extension.foo.smudge
  git config --unset lfs.extension.foo.priority

  # DO
  result=$(git lfs dedup --test 2>&1) && true

  # Verify: This platform and repository support file de-duplication.
  echo "$result" | grep 'This platform and repository support file de-duplication.'
)
end_test

begin_test "dedup dirty workdir"
(
  set -e

  reponame="dedup_dirty_workdir"
  git init $reponame
  cd $reponame

  # Make working tree dirty.
  echo "test data" > a.dat
  git add a.dat
  git commit -m "first commit"
  echo "modify" >> a.dat

  # DO
  result=$(git lfs dedup 2>&1) && true
  if ( echo $result | grep "This system does not support de-duplication." ); then
    exit
  fi

  # Verify: Working tree is dirty. Please commit or reset your change.
  echo "$result" | grep 'Working tree is dirty. Please commit or reset your change.'
)
end_test