<commit_before>#!/usr/bin/env bash

. "test/testlib.sh"

begin_test "smudge"
(
  set -e

  reponame="$(basename "$0" ".sh")"
  setup_remote_repo "$reponame"
  clone_repo "$reponame" repo

  git lfs track "*.dat"
  echo "smudge a" > a.dat
  git add .gitattributes a.dat
  git commit -m "add a.dat"

  # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects
  output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
  [ "smudge a" = "$output" ]

  git push origin master

  # download it from the git lfs server
  rm -rf .git/lfs/objects
  output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
  [ "smudge a" = "$output" ]
)
end_test

begin_test "smudge --info"
(
  set -e

  cd repo
  output="$(pointer aaaaa15df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 123 | git lfs smudge --info)"
  [ "123 --" = "$output" ]
)
end_test

begin_test "smudge with temp file"
(
  set -e
    set -e

    reponame="$(basename "$0" ".sh")-with-temp"
    setup_remote_repo "$reponame"
    clone_repo "$reponame" repo

    git lfs track "*.dat"
    echo "smudge a" > a.dat
    git add .gitattributes a.dat
    git commit -m "add a.dat"

    git push origin master
    rm -rf .git/lfs/objects
    mkdir -p .git/lfs/tmp/objects
    touch .git/lfs/tmp/objects/fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254-1
    pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | GIT_TRACE=5 git lfs smudge | tee smudge.log
    [ "smudge a" = "$(cat smudge.log)" ] || {
      git lfs logs last
      exit 1
    }
)
end_test

begin_test "smudge with invalid pointer"
(
  set -e

  cd repo<commit_msg>re-use test setup from earlier tests<commit_after>#!/usr/bin/env bash

. "test/testlib.sh"

begin_test "smudge"
(
  set -e

  reponame="$(basename "$0" ".sh")"
  setup_remote_repo "$reponame"
  clone_repo "$reponame" repo

  git lfs track "*.dat"
  echo "smudge a" > a.dat
  git add .gitattributes a.dat
  git commit -m "add a.dat"

  # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects
  output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
  [ "smudge a" = "$output" ]

  git push origin master

  # download it from the git lfs server
  rm -rf .git/lfs/objects
  output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
  [ "smudge a" = "$output" ]
)
end_test

begin_test "smudge --info"
(
  set -e

  cd repo
  output="$(pointer aaaaa15df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 123 | git lfs smudge --info)"
  [ "123 --" = "$output" ]
)
end_test

begin_test "smudge with temp file"
(
  set -e

  cd repo

  rm -rf .git/lfs/objects
  mkdir -p .git/lfs/tmp/objects
  touch .git/lfs/tmp/objects/fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254-1
  pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | GIT_TRACE=5 git lfs smudge | tee smudge.log
  [ "smudge a" = "$(cat smudge.log)" ] || {
    rm -rf .git/lfs/tmp
    git lfs logs last
    exit 1
  }
)
end_test

begin_test "smudge with invalid pointer"
(
  set -e

  cd repo
{'fraction_non_alphanumeric': 0.11080332409972299, 'fraction_numerical': 0.12096029547553093, 'mean_word_length': 3.5839210155148096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3995409', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1418, 'n_words': 316}