From 3b3ba084ead1f9f14a6e0ac8ff1a1f73779bc527 Mon Sep 17 00:00:00 2001 From: Jerome Reybert <jreybert@gmail.com> Date: Tue, 1 Dec 2015 12:00:12 +0100 Subject: [PATCH] autoload/magit/git.vim: fix modified/untracked content in submodule (fix #49) --- autoload/magit/git.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index b009105..6e5f12f 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -95,13 +95,24 @@ function! magit#git#git_diff(filename, status, mode) silent let diff_list=magit#utils#systemlist(git_cmd) if ( empty(diff_list) ) echohl WarningMsg - echom "diff command \"" . diff_cmd . "\" returned nothing" + echom "diff command \"" . git_cmd . "\" returned nothing" echohl None throw 'diff error' endif return diff_list endfunction +" magit#git#sub_check: this function checks if given submodule has modified or +" untracked content +" param[in] submodule: submodule path +" param[in] check_level: can be modified or untracked +function! magit#git#sub_check(submodule, check_level) + let ignore_flag = ( a:check_level == 'modified' ) ? + \ '--ignore-submodules=untracked' : '' + let git_cmd="git status --porcelain " . ignore_flag . " " . a:submodule + return ( !empty(magit#utils#systemlist(git_cmd)) ) +endfunction + " magit#git#git_sub_summary: helper function to get diff of a submodule " nota: when git fail (due to misformated patch for example), an error " message is raised. @@ -113,8 +124,16 @@ function! magit#git#git_sub_summary(filename, mode) \ .a:filename silent let diff_list=magit#utils#systemlist(git_cmd) if ( empty(diff_list) ) + if ( a:mode == 'unstaged' ) + if ( magit#git#sub_check(a:filename, 'modified') ) + return "modified content" + endif + if ( magit#git#sub_check(a:filename, 'untracked') ) + return "untracked content" + endif + endif echohl WarningMsg - echom "diff command \"" . diff_cmd . "\" returned nothing" + echom "diff command \"" . git_cmd . "\" returned nothing" echohl None throw 'diff error' endif -- GitLab