我想自动测试一组补丁仍然干净地适用于(更新的)代码库。为此,我打算运行
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
不是这里任务的正确工具。)
答案 0 :(得分:3)
使用-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