]> granicus.if.org Git - vim/commitdiff
patch 8.2.4014: git and gitcommit file types not properly recognized v8.2.4014
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Jan 2022 20:56:38 +0000 (20:56 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Jan 2022 20:56:38 +0000 (20:56 +0000)
Problem:    Git and gitcommit file types not properly recognized.
Solution:   Adjust filetype detection. (Tim Pope, closes #9477)

runtime/filetype.vim
runtime/scripts.vim
src/testdir/test_filetype.vim
src/version.c

index c92ae69e1d4a0efe20550a961caead712259589f..f6ba012f3793f7c05a208e41b22cc9e1d3379fc0 100644 (file)
@@ -497,7 +497,7 @@ au BufNewFile,BufRead */debian/patches/*    call dist#ft#Dep3patch()
 " Diff files
 au BufNewFile,BufRead *.diff,*.rej             setf diff
 au BufNewFile,BufRead *.patch
-       \ if getline(1) =~ '^From [0-9a-f]\{40\} Mon Sep 17 00:00:00 2001$' |
+       \ if getline(1) =~# '^From [0-9a-f]\{40,\} Mon Sep 17 00:00:00 2001$' |
        \   setf gitsendemail |
        \ else |
        \   setf diff |
@@ -676,6 +676,7 @@ autocmd BufRead,BufNewFile *.gift           setf gift
 
 " Git
 au BufNewFile,BufRead COMMIT_EDITMSG,MERGE_MSG,TAG_EDITMSG     setf gitcommit
+au BufNewFile,BufRead NOTES_EDITMSG,EDIT_DESCRIPTION           setf gitcommit
 au BufNewFile,BufRead *.git/config,.gitconfig,/etc/gitconfig   setf gitconfig
 au BufNewFile,BufRead */.config/git/config                     setf gitconfig
 au BufNewFile,BufRead .gitmodules,*.git/modules/*/config       setf gitconfig
@@ -684,12 +685,8 @@ if !empty($XDG_CONFIG_HOME)
 endif
 au BufNewFile,BufRead git-rebase-todo          setf gitrebase
 au BufRead,BufNewFile .gitsendemail.msg.?????? setf gitsendemail
-au BufNewFile,BufRead .msg.[0-9]*
-      \ if getline(1) =~ '^From.*# This line is ignored.$' |
-      \   setf gitsendemail |
-      \ endif
 au BufNewFile,BufRead *.git/*
-      \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
+      \ if getline(1) =~# '^\x\{40,\}\>\|^ref: ' |
       \   setf git |
       \ endif
 
index 3790b1c10ff46d4e6faa55407fe4292e5af68d65..e41405a6c54abe59ada42642501910258a623681 100644 (file)
@@ -384,7 +384,7 @@ else
     set ft=scheme
 
   " Git output
-  elseif s:line1 =~# '^\(commit\|tree\|object\) \x\{40\}\>\|^tag \S\+$'
+  elseif s:line1 =~# '^\(commit\|tree\|object\) \x\{40,\}\>\|^tag \S\+$'
     set ft=git
 
    " Gprof (gnu profiler)
index 89dd8f2043ca5ca7d0bcef948df06121455bb9d5..d8a2d79f6ea716a7315c702bd28fd3c60d8c4632 100644 (file)
@@ -195,7 +195,7 @@ let s:filename_checks = {
     \ 'gedcom': ['file.ged', 'lltxxxxx.txt', '/tmp/lltmp', '/tmp/lltmp-file', 'any/tmp/lltmp', 'any/tmp/lltmp-file'],
     \ 'gemtext': ['file.gmi', 'file.gemini'],
     \ 'gift': ['file.gift'],
-    \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG'],
+    \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG', 'NOTES_EDITMSG', 'EDIT_DESCRIPTION'],
     \ 'gitconfig': ['file.git/config', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig', '/etc/gitconfig.d/file', '/.gitconfig.d/file', 'any/.config/git/config', 'any/.gitconfig.d/file', 'some.git/config', 'some.git/modules/any/config'],
     \ 'gitolite': ['gitolite.conf', '/gitolite-admin/conf/file', 'any/gitolite-admin/conf/file'],
     \ 'gitrebase': ['git-rebase-todo'],
@@ -1070,4 +1070,55 @@ func Test_dep3patch_file()
   call delete('debian/patches', 'rf')
 endfunc
 
+func Test_patch_file()
+  filetype on
+
+  call writefile([], 'Xfile.patch')
+  split Xfile.patch
+  call assert_equal('diff', &filetype)
+  bwipe!
+
+  call writefile(['From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch')
+  split Xfile.patch
+  call assert_equal('gitsendemail', &filetype)
+  bwipe!
+
+  call writefile(['From 0000000000000000000000000000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch')
+  split Xfile.patch
+  call assert_equal('gitsendemail', &filetype)
+  bwipe!
+
+  call delete('Xfile.patch')
+  filetype off
+endfunc
+
+func Test_git_file()
+  filetype on
+
+  call assert_true(mkdir('Xrepo.git', 'p'))
+
+  call writefile([], 'Xrepo.git/HEAD')
+  split Xrepo.git/HEAD
+  call assert_equal('', &filetype)
+  bwipe!
+
+  call writefile(['0000000000000000000000000000000000000000'], 'Xrepo.git/HEAD')
+  split Xrepo.git/HEAD
+  call assert_equal('git', &filetype)
+  bwipe!
+
+  call writefile(['0000000000000000000000000000000000000000000000000000000000000000'], 'Xrepo.git/HEAD')
+  split Xrepo.git/HEAD
+  call assert_equal('git', &filetype)
+  bwipe!
+
+  call writefile(['ref: refs/heads/master'], 'Xrepo.git/HEAD')
+  split Xrepo.git/HEAD
+  call assert_equal('git', &filetype)
+  bwipe!
+
+  call delete('Xrepo.git', 'rf')
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 3fb926228d9075c619bceda0c859782053efa6d1..dcebe58851ed4e288e1fd616aeb467aff6708ec1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4014,
 /**/
     4013,
 /**/