2016-05-11 117 views
1

我想自动测试一组补丁程序,仍然适用于(更新的)代码库。为此,我打算跑补丁:以非交互模式运行

patch -p 1 < path/to/patch0.patch 

所有补丁patch*.patch,检查此命令的返回码和存储在某个地方。不幸的是,在某些情况下,patch似乎以交互方式工作。一个典型的输出需要交互将会

can't find file to patch at input line 44 
Perhaps you used the wrong -p or --strip option? 
The text leading up to this was: 
-------------------------- 
|Index: foo/docs/faq.html 
|=================================================================== 
|--- foo.orig/docs/faq.html 
|+++ foo/docs/faq.html 
-------------------------- 
File to patch: 

是否有一种方式来运行patch非交互式? (也许patch不是任务的合适的工具在这里。)

回答

2

使用-f--force)选项:

echo a > a 
echo b > b 
diff -Nu a b > p 
rm a b 
patch -p 1 < p 
can't find file to patch at input line 3 
Perhaps you used the wrong -p or --strip option? 
The text leading up to this was: 
-------------------------- 
|--- a 2016-05-11 16:16:24.115481324 +0700 
|+++ b 2016-05-11 16:16:24.115481324 +0700 
-------------------------- 
File to patch: 

(询问输入)。然而,

patch -f -p 1 < p 
can't find file to patch at input line 3 
Perhaps you used the wrong -p or --strip option? 
The text leading up to this was: 
-------------------------- 
|--- a 2016-05-11 16:16:24.115481324 +0700 
|+++ b 2016-05-11 16:16:24.115481324 +0700 
-------------------------- 
No file to patch. Skipping patch. 
1 out of 1 hunk ignored 

与退出状态退出($?)1:

echo $? 
1