aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormpeterv <mpeterval@gmail.com>2015-10-17 10:46:44 +0300
committermpeterv <mpeterval@gmail.com>2015-10-17 11:44:42 +0300
commit7886cffec0721ecfb733384946d7a4399c43b897 (patch)
treec9ffa7086414a2bfe4a08358726c709d0e94a193
parent8fe1bbd627bae2da2d1b7d8e376a35ebf5626d2e (diff)
downloadluarocks-7886cffec0721ecfb733384946d7a4399c43b897.tar.gz
luarocks-7886cffec0721ecfb733384946d7a4399c43b897.tar.bz2
luarocks-7886cffec0721ecfb733384946d7a4399c43b897.zip
Fix patch error message when source is different
check_patched() relies on throwing and catching string 'nomatch'. Pass 0 as the second argument for error() when throwing to avoid location info being added to the message. Fixes lack of error when patch should fail with "source is different" error.
-rw-r--r--src/luarocks/tools/patch.lua17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua
index b53bad61..c4715cd6 100644
--- a/src/luarocks/tools/patch.lua
+++ b/src/luarocks/tools/patch.lua
@@ -455,16 +455,15 @@ local function find_hunks(file, hunks)
455end 455end
456 456
457local function check_patched(file, hunks) 457local function check_patched(file, hunks)
458 local matched = true
459 local lineno = 1 458 local lineno = 1
460 local ok, err = pcall(function() 459 local ok, err = pcall(function()
461 if #file == 0 then 460 if #file == 0 then
462 error 'nomatch' 461 error('nomatch', 0)
463 end 462 end
464 for hno, h in ipairs(hunks) do 463 for hno, h in ipairs(hunks) do
465 -- skip to line just before hunk starts 464 -- skip to line just before hunk starts
466 if #file < h.starttgt then 465 if #file < h.starttgt then
467 error 'nomatch' 466 error('nomatch', 0)
468 end 467 end
469 lineno = h.starttgt 468 lineno = h.starttgt
470 for _, hline in ipairs(h.text) do 469 for _, hline in ipairs(h.text) do
@@ -473,22 +472,18 @@ local function check_patched(file, hunks)
473 local line = file[lineno] 472 local line = file[lineno]
474 lineno = lineno + 1 473 lineno = lineno + 1
475 if #line == 0 then 474 if #line == 0 then
476 error 'nomatch' 475 error('nomatch', 0)
477 end 476 end
478 if endlstrip(line) ~= endlstrip(hline:sub(2)) then 477 if endlstrip(line) ~= endlstrip(hline:sub(2)) then
479 warning(format("file is not patched - failed hunk: %d", hno)) 478 warning(format("file is not patched - failed hunk: %d", hno))
480 error 'nomatch' 479 error('nomatch', 0)
481 end 480 end
482 end 481 end
483 end 482 end
484 end 483 end
485 end) 484 end)
486 if err == 'nomatch' then 485 -- todo: display failed hunk, i.e. expected/found
487 matched = false 486 return err ~= 'nomatch'
488 end
489 -- todo: display failed hunk, i.e. expected/found
490
491 return matched
492end 487end
493 488
494local function patch_hunks(srcname, tgtname, hunks) 489local function patch_hunks(srcname, tgtname, hunks)