Commits

ZyX_I committed f9dc307

@%aurum/drivers/git: Fixed grep in case it fails to find anything

Comments (0)

Files changed (1)

autoload/aurum/drivers/git.vim

 function s:git.grep(repo, pattern, files, revisions, ic, wdfiles)
     let args=['-e', a:pattern, '--']+a:files
     let kwargs={'full-name': 1, 'extended-regexp': 1, 'n': 1, 'z': 1}
-    let gitargs=[a:repo, 'grep', args, kwargs, 1]
     let r=[]
     if !empty(a:revisions)
         let revs=[]
             unlet s
         endfor
         call extend(args, revs, 2)
-        for [revfile, lnum, text] in s:F.parsegrep(call(s:F.git, gitargs, {}))
+    endif
+    let [lines, exit_code]=s:F.git(a:repo, 'grep', args, kwargs, 1, 0)
+    if exit_code
+        " Grep failed because it has found nothing
+        if lines ==# ['']
+            return []
+        " Grep failed for another reason
+        else
+            call s:_f.throw('grepf', a:repo.path, join(lines, "\n"))
+        endif
+    endif
+    if empty(a:revisions)
+        for [file, lnum, text] in s:F.parsegrep(lines)
+            let r+=[{'filename': file, 'lnum': lnum, 'text': text}]
+        endfor
+    else
+        for [revfile, lnum, text] in s:F.parsegrep(lines)
             let cidx=stridx(revfile, ':')
             let rev=revfile[:(cidx-1)]
             let file=revfile[(cidx+1):]
             let r+=[{'filename': [rev, file], 'lnum': lnum, 'text': text}]
         endfor
-    else
-        for [file, lnum, text] in s:F.parsegrep(call(s:F.git, gitargs, {}))
-            let r+=[{'filename': file, 'lnum': lnum, 'text': text}]
-        endfor
     endif
     return r
 endfunction