aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_cmds2.c22
-rw-r--r--test/functional/legacy/packadd_spec.lua9
2 files changed, 27 insertions, 4 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 4e3fc86539..f46e4108f4 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -2683,10 +2683,24 @@ static int APP_BOTH;
static void add_pack_plugin(char_u *fname, void *cookie)
{
- if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)fname) == NULL) {
- // directory is not yet in 'runtimepath', add it
- if (add_pack_dir_to_rtp(fname) == FAIL) {
- return;
+ if (cookie != &APP_LOAD) {
+ char *buf = xmalloc(MAXPATHL);
+ bool found = false;
+
+ const char *p = (const char *)p_rtp;
+ while (*p != NUL) {
+ copy_option_part((char_u **)&p, (char_u *)buf, MAXPATHL, ",");
+ if (path_fnamecmp(buf, (char *)fname) == 0) {
+ found = true;
+ break;
+ }
+ }
+ xfree(buf);
+ if (!found) {
+ // directory is not yet in 'runtimepath', add it
+ if (add_pack_dir_to_rtp(fname) == FAIL) {
+ return;
+ }
}
}
diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua
index a73beef0cd..ca3757ad3c 100644
--- a/test/functional/legacy/packadd_spec.lua
+++ b/test/functional/legacy/packadd_spec.lua
@@ -57,6 +57,15 @@ describe('packadd', function()
call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp)
call assert_match(Escape(expand(s:plugdir . '/after$')), &rtp)
+ " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
+ call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
+ let rtp = &rtp
+ packadd myte
+
+ " Check the path of 'myte' is added
+ call assert_true(len(&rtp) > len(rtp))
+ call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp)
+
" Check exception
call assert_fails("packadd directorynotfound", 'E919:')
call assert_fails("packadd", 'E471:')