<commit_before>" whenever we open a gitcommit, pull up the staged changes
if !&previewwindow
  try
    let s:pos = getcurpos()
    call gitmagic#ShowIndex()
  finally
    call setpos('.', s:pos)
  endtry
endif

python3 << ENDOFPYTHON
import vim
import subprocess
import os.path

def FTPluginGitCommitInsertPrefix():
  buf = vim.current.buffer

  # if the starting line already has text, there's nothing we can do
  if buf[0] != '':
    return

  cmd = ['git', 'status', '--porcelain=v1']
  lines = subprocess.check_output(cmd).decode('utf-8').splitlines()
  files = []
  for line in lines:
    index = line[0]
    # ignore unmodified (' ') and untracked ('?') files
    if index in (' ', '?'):
      continue
    filename = line[3:]
    files.append(filename)
  longest = os.path.commonprefix(files)

  cmd = ['git', 'rev-parse', '--show-toplevel']
  root = subprocess.check_output(cmd).decode('utf-8')

  lookfor = ('setup.py', 'Dockerfile', 'setup.cfg')
  maxexamine = 3

  # start at the deepest level looking for one of our special files
  parts = os.path.split(longest)

  for examine in range(3, 0, -1):
    prefix = os.path.join(*parts[:examine])
    for special in lookfor:
      if os.path.exists(os.path.join(root, prefix, special)):
        break

  buf[0] = prefix + ': '
  vim.command('setlocal modified')

ENDOFPYTHON

" is the first line of the file blank?
if !&l:modified
  python3 FTPluginGitCommitInsertPrefix()
endif<commit_msg>vim/after/ftplugin/gitcommit.vim: fix prefix insertion logic<commit_after>" whenever we open a gitcommit, pull up the staged changes
if !&previewwindow
  try
    let s:pos = getcurpos()
    call gitmagic#ShowIndex()
  finally
    call setpos('.', s:pos)
  endtry
endif

python3 << ENDOFPYTHON
import vim
import subprocess
import os.path

def FTPluginGitCommitInsertPrefix():
  buf = vim.current.buffer

  # if the starting line already has text, there's nothing we can do
  if buf[0] != '':
    return

  cmd = ['git', 'status', '--porcelain=v1']
  lines = subprocess.check_output(cmd).decode('utf-8').splitlines()
  files = []
  for line in lines:
    index = line[0]
    # ignore unmodified (' ') and untracked ('?') files
    if index in (' ', '?'):
      continue
    filename = line[3:]
    files.append(filename)
  longest = os.path.commonprefix(files)

  cmd = ['git', 'rev-parse', '--show-toplevel']
  root = subprocess.check_output(cmd).decode('utf-8').strip()

  lookfor = ('setup.py', 'Dockerfile', 'setup.cfg')
  maxexamine = 3

  # start at the deepest level looking for one of our special files
  parts = longest.split('/')

  def _insertprefix(prefix):
    buf[0] = prefix + ': '
    vim.command('setlocal modified')

  def _tryprefix(prefix):
    for special in lookfor:
      what = os.path.join(root, prefix, special)
      if os.path.exists(what):
        _insertprefix(prefix)
        return True
    return False

  for examine in range(3, 0, -1):
    prefix = os.path.join(*parts[:examine])
    if _tryprefix(prefix):
      break
  else:
    _insertprefix(longest)

ENDOFPYTHON

" is the first line of the file blank?
if !&l:modified
  python3 FTPluginGitCommitInsertPrefix()
endif
{'fraction_non_alphanumeric': 0.13238095238095238, 'fraction_numerical': 0.008253968253968255, 'mean_word_length': 3.4442877291960508, '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': '6938536', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1039, 'n_words': 298}