Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
vimagit
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
jreybert
vimagit
Commits
c10c9cad
Commit
c10c9cad
authored
Oct 30, 2015
by
Jerome Reybert
Browse files
Options
Downloads
Patches
Plain Diff
plugin/magit.vim: move git_(un)apply helper functions to utils.vim
parent
87cbc4f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
autoload/magit/utils.vim
+48
-0
48 additions, 0 deletions
autoload/magit/utils.vim
plugin/magit.vim
+3
-49
3 additions, 49 deletions
plugin/magit.vim
with
51 additions
and
49 deletions
autoload/magit/utils.vim
+
48
−
0
View file @
c10c9cad
...
@@ -33,6 +33,54 @@ function! magit#utils#git_dir()
...
@@ -33,6 +33,54 @@ function! magit#utils#git_dir()
return
s:magit_git_dir
return
s:magit_git_dir
endfunction
endfunction
" magit#utils#git_apply: helper function to stage a selection
" nota: when git fail (due to misformated patch for example), an error
" message is raised.
" param[in] selection: the text to stage. It must be a patch, i.e. a diff
" header plus one or more hunks
" return: no
function
!
magit#utils#git_apply
(
header
,
selection
)
let
selection
=
magit#utils#flatten
(
a:header
+
a:selection
)
if
(
selection
[
-1
]
!~
'^$'
)
let
selection
+=
[
''
]
endif
let
git_cmd
=
"git apply --recount --no-index --cached -"
silent
let
git_result
=
magit#utils#
system
(
git_cmd
,
selection
)
if
(
v
:
shell_error
!=
0
)
echoerr
"Git error: "
.
git_result
echoerr
"Git cmd: "
.
git_cmd
echoerr
"Tried to aply this"
echoerr
string
(
selection
)
endif
endfunction
" magit#utils#git_unapply: helper function to unstage a selection
" nota: when git fail (due to misformated patch for example), an error
" message is raised.
" param[in] selection: the text to stage. It must be a patch, i.e. a diff
" header plus one or more hunks
" return: no
function
!
magit#utils#git_unapply
(
header
,
selection
,
mode
)
let
cached_flag
=
''
if
(
a:mode
==
'staged'
)
let
cached_flag
=
' --cached '
endif
let
selection
=
magit#utils#flatten
(
a:header
+
a:selection
)
if
(
selection
[
-1
]
!~
'^$'
)
let
selection
+=
[
''
]
endif
silent
let
git_result
=
magit#utils#
system
(
\
"git apply --recount --no-index "
.
cached_flag
.
" --reverse - "
,
\
selection
)
if
(
v
:
shell_error
!=
0
)
echoerr
"Git error: "
.
git_result
echoerr
"Tried to unaply this"
echoerr
string
(
selection
)
endif
endfunction
" s:magit#utils#is_binary: check if file is a binary file
" s:magit#utils#is_binary: check if file is a binary file
" param[in] filename: the file path. it must quoted if it contains spaces
" param[in] filename: the file path. it must quoted if it contains spaces
function
!
magit#utils#is_binary
(
filename
)
function
!
magit#utils#is_binary
(
filename
)
...
...
This diff is collapsed.
Click to expand it.
plugin/magit.vim
+
3
−
49
View file @
c10c9cad
...
@@ -380,52 +380,6 @@ function! s:mg_select_hunk_block()
...
@@ -380,52 +380,6 @@ function! s:mg_select_hunk_block()
\
g:magit_file_re
)
\
g:magit_file_re
)
endfunction
endfunction
" s:mg_git_apply: helper function to stage a selection
" nota: when git fail (due to misformated patch for example), an error
" message is raised.
" param[in] selection: the text to stage. It must be a patch, i.e. a diff
" header plus one or more hunks
" return: no
function
!
s:mg_git_apply
(
header
,
selection
)
let
selection
=
magit#utils#flatten
(
a:header
+
a:selection
)
if
(
selection
[
-1
]
!~
'^$'
)
let
selection
+=
[
''
]
endif
let
git_cmd
=
"git apply --recount --no-index --cached -"
silent
let
git_result
=
magit#utils#
system
(
git_cmd
,
selection
)
if
(
v
:
shell_error
!=
0
)
echoerr
"Git error: "
.
git_result
echoerr
"Git cmd: "
.
git_cmd
echoerr
"Tried to aply this"
echoerr
string
(
selection
)
endif
endfunction
" s:mg_git_unapply: helper function to unstage a selection
" nota: when git fail (due to misformated patch for example), an error
" message is raised.
" param[in] selection: the text to stage. It must be a patch, i.e. a diff
" header plus one or more hunks
" return: no
function
!
s:mg_git_unapply
(
header
,
selection
,
mode
)
let
cached_flag
=
''
if
(
a:mode
==
'staged'
)
let
cached_flag
=
' --cached '
endif
let
selection
=
magit#utils#flatten
(
a:header
+
a:selection
)
if
(
selection
[
-1
]
!~
'^$'
)
let
selection
+=
[
''
]
endif
silent
let
git_result
=
magit#utils#
system
(
\
"git apply --recount --no-index "
.
cached_flag
.
" --reverse - "
,
\
selection
)
if
(
v
:
shell_error
!=
0
)
echoerr
"Git error: "
.
git_result
echoerr
"Tried to unaply this"
echoerr
string
(
selection
)
endif
endfunction
" s:mg_create_diff_from_select: craft the diff to apply from a selection
" s:mg_create_diff_from_select: craft the diff to apply from a selection
" in a chunk
" in a chunk
" remarks: it works with full lines, and can not span over multiple chunks
" remarks: it works with full lines, and can not span over multiple chunks
...
@@ -726,14 +680,14 @@ function! magit#stage_block(selection, discard) abort
...
@@ -726,14 +680,14 @@ function! magit#stage_block(selection, discard) abort
call
magit#utils#
system
(
'git add '
.
call
magit#utils#
system
(
'git add '
.
\
magit#utils#add_quotes
(
filename
))
\
magit#utils#add_quotes
(
filename
))
else
else
call
<
SID
>
mg_
git_apply
(
header
,
a:selection
)
call
magit#utils#
git_apply
(
header
,
a:selection
)
endif
endif
elseif
(
section
==
'staged'
)
elseif
(
section
==
'staged'
)
if
(
file
.
must_be_added
()
)
if
(
file
.
must_be_added
()
)
call
magit#utils#
system
(
'git reset '
.
call
magit#utils#
system
(
'git reset '
.
\
magit#utils#add_quotes
(
filename
))
\
magit#utils#add_quotes
(
filename
))
else
else
call
<
SID
>
mg_
git_unapply
(
header
,
a:selection
,
'staged'
)
call
magit#utils#
git_unapply
(
header
,
a:selection
,
'staged'
)
endif
endif
else
else
echoerr
"Must be in \""
.
echoerr
"Must be in \""
.
...
@@ -745,7 +699,7 @@ function! magit#stage_block(selection, discard) abort
...
@@ -745,7 +699,7 @@ function! magit#stage_block(selection, discard) abort
if
(
file
.
must_be_added
()
)
if
(
file
.
must_be_added
()
)
call
delete
(
filename
)
call
delete
(
filename
)
else
else
call
<
SID
>
mg_
git_unapply
(
header
,
a:selection
,
'unstaged'
)
call
magit#utils#
git_unapply
(
header
,
a:selection
,
'unstaged'
)
endif
endif
else
else
echoerr
"Must be in \""
.
echoerr
"Must be in \""
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment