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

set -e

SCRIPTS_DIR=$(dirname $0)

function help() {
  cat <<HELP
Usage: migrate.sh [--no-transform] SOURCE_FILE DESTINATION_FILE
Move the SOURCE_FILE to DESTINATION_FILE, applying the transformation described
by this project's "transform.js" script.
HELP
}

SOURCE_FILE=$1
DESTINATION_FILE=$2
if [[ "$1" == "--no-transform" ]]; then
  SOURCE_FILE=$2
  DESTINATION_FILE=$3
  NO_TRANSFORM=1
fi

if [[ "$1" == "-h" || "$1" == "--help" ]]; then help; exit; fi

if [[ "$SOURCE_FILE" == "" || "$DESTINATION_FILE" == "" ]]; then
  help;
  exit 1;
fi

cp $SOURCE_FILE $DESTINATION_FILE
rm $SOURCE_FILE

if [[ ! $NO_TRANSFORM -eq 1 ]]; then
  $SCRIPTS_DIR/transform.js --in-place $DESTINATION_FILE
fi<commit_msg>Fail gracefully when errors occur during migration<commit_after>#!/usr/bin/env bash

SCRIPTS_DIR=$(dirname $0)

function help() {
  cat <<HELP
Usage: migrate.sh [--no-transform] SOURCE_FILE DESTINATION_FILE
Move the SOURCE_FILE to DESTINATION_FILE, applying the transformation described
by this project's "transform.js" script.
HELP
}

SOURCE_FILE=$1
DESTINATION_FILE=$2
if [[ "$1" == "--no-transform" ]]; then
  SOURCE_FILE=$2
  DESTINATION_FILE=$3
  NO_TRANSFORM=1
fi

if [[ "$1" == "-h" || "$1" == "--help" ]]; then help; exit; fi

if [[ "$SOURCE_FILE" == "" || "$DESTINATION_FILE" == "" ]]; then
  help;
  exit 1;
fi

cp $SOURCE_FILE $DESTINATION_FILE

if [[ $? -ne 0 ]]; then
  echo "Error: Couldn't copy $SOURCE_FILE to $DESTINATION_FILE"
  exit 1;
fi

if [[ ! $NO_TRANSFORM -eq 1 ]]; then
  $SCRIPTS_DIR/transform.js --in-place $DESTINATION_FILE

  if [[ $? -ne 0 ]]; then
    echo "Error: Could not transform $SOURCE_FILE"
    rm $DESTINATION_FILE
    exit 1;
  fi
fi

rm $SOURCE_FILE
{'fraction_non_alphanumeric': 0.15935334872979215, 'fraction_numerical': 0.015011547344110854, 'mean_word_length': 4.235649546827794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873317', 'n_tokens_mistral': 680, 'n_tokens_neox': 667, 'n_words': 174}