<commit_before>#:  * `update` [`--merge`]:
#:    Fetch the newest version of Homebrew and all formulae from GitHub using
#:     `git`(1).
#:
#:    If `--merge` is specified then `git merge` is used to include updates
#:      (rather than `git rebase`).

brew() {
  "$HOMEBREW_BREW_FILE" "$@"
}

git() {
  "$HOMEBREW_LIBRARY/ENV/scm/git" "$@"
}

git_init_if_necessary() {
  if [[ -n "$HOMEBREW_OSX" ]]
  then
    OFFICIAL_REMOTE="https://github.com/Homebrew/brew.git"
  else
    OFFICIAL_REMOTE="https://github.com/Linuxbrew/brew.git"
  fi

  if [[ ! -d ".git" ]]
  then
    set -e
    trap '{ rm -rf .git; exit 1; }' EXIT
    git init
    git config --bool core.autocrlf false
    git config remote.origin.url "$OFFICIAL_REMOTE"
    git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master
    git reset --hard origin/master
    SKIP_FETCH_HOMEBREW_REPOSITORY=1
    set +e
    trap - EXIT
  fi
}

rename_taps_dir_if_necessary() {
  local tap_dir
  local tap_dir_basename
  local user
  local repo

  for tap_dir in "$HOMEBREW_LIBRARY"/Taps/*
  do
    [[ -d "$tap_dir/.git" ]] || continue
    tap_dir_basename="${tap_dir##*/}"
    if [[ "$tap_dir_basename" = *"-"* ]]
    then
      # only replace the *last* dash: yes, tap filenames suck
      user="$(echo "${tap_dir_basename%-*}" | tr "[:upper:]" "[:lower:]")"
      repo="$(echo "${tap_dir_basename:${#user}+1}" | tr "[:upper:]" "[:lower:]")"
      mkdir -p "$HOMEBREW_LIBRARY/Taps/$user"
      mv "$tap_dir" "$HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo"

      if [[ ${#${tap_dir_basename//[^\-]}} -gt 1 ]]
      then
        echo "Homebrew changed the structure of Taps like <someuser>/<sometap>." >&2
        echo "So you may need to rename $HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo manually." >&2
      fi
    else
      echo "Homebrew changed the structure of Taps like <someuser>/<sometap>. " >&2
      echo "$tap_dir is an incorrect Tap path." >&2
      echo "So you may need to rename it to $HOMEBREW_LIBRARY/Taps/<someuser>/homebrew-<sometap> manually." >&2<commit_msg>update: fix hyphen counting (legacy tap renaming)<commit_after>#:  * `update` [`--merge`]:
#:    Fetch the newest version of Homebrew and all formulae from GitHub using
#:     `git`(1).
#:
#:    If `--merge` is specified then `git merge` is used to include updates
#:      (rather than `git rebase`).

brew() {
  "$HOMEBREW_BREW_FILE" "$@"
}

git() {
  "$HOMEBREW_LIBRARY/ENV/scm/git" "$@"
}

git_init_if_necessary() {
  if [[ -n "$HOMEBREW_OSX" ]]
  then
    OFFICIAL_REMOTE="https://github.com/Homebrew/brew.git"
  else
    OFFICIAL_REMOTE="https://github.com/Linuxbrew/brew.git"
  fi

  if [[ ! -d ".git" ]]
  then
    set -e
    trap '{ rm -rf .git; exit 1; }' EXIT
    git init
    git config --bool core.autocrlf false
    git config remote.origin.url "$OFFICIAL_REMOTE"
    git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    git fetch --force --depth=1 origin refs/heads/master:refs/remotes/origin/master
    git reset --hard origin/master
    SKIP_FETCH_HOMEBREW_REPOSITORY=1
    set +e
    trap - EXIT
  fi
}

rename_taps_dir_if_necessary() {
  local tap_dir
  local tap_dir_basename
  local tap_dir_hyphens
  local user
  local repo

  for tap_dir in "$HOMEBREW_LIBRARY"/Taps/*
  do
    [[ -d "$tap_dir/.git" ]] || continue
    tap_dir_basename="${tap_dir##*/}"
    if [[ "$tap_dir_basename" = *"-"* ]]
    then
      # only replace the *last* dash: yes, tap filenames suck
      user="$(echo "${tap_dir_basename%-*}" | tr "[:upper:]" "[:lower:]")"
      repo="$(echo "${tap_dir_basename:${#user}+1}" | tr "[:upper:]" "[:lower:]")"
      mkdir -p "$HOMEBREW_LIBRARY/Taps/$user"
      mv "$tap_dir" "$HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo"

      tap_dir_hyphens="${tap_dir_basename//[^\-]}"
      if [[ ${#tap_dir_hyphens} -gt 1 ]]
      then
        echo "Homebrew changed the structure of Taps like <someuser>/<sometap>." >&2
        echo "So you may need to rename $HOMEBREW_LIBRARY/Taps/$user/homebrew-$repo manually." >&2
      fi
    else
      echo "Homebrew changed the structure of Taps like <someuser>/<sometap>. " >&2
      echo "$tap_dir is an incorrect Tap path." >&2
      echo "So you may need to rename it to $HOMEBREW_LIBRARY/Taps/<someuser>/homebrew-<sometap> manually." >&2
{'fraction_non_alphanumeric': 0.16200091785222578, 'fraction_numerical': 0.005048187241854061, 'mean_word_length': 3.112264150943396, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 4, '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': '7563633', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1592, 'n_words': 392}