2016-05-11 41 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