我正在尝试编写一个shell脚本来重现我在使用Mercurial的搁置扩展时遇到的情况。
这需要中断Mercurial的命令行用户界面(UI)提供的提示。请参见以下脚本
rm -rf test-shelveinterrupt
hg init test-shelveinterrupt
cd test-shelveinterrupt
hg branch foo
echo "First line of foo" >> foo
hg add foo
hg ci -m "First line of foo" foo
echo "Second line of foo" >> foo
hg shelve
hg up null
hg branch bar
echo "First line of bar" >> bar
hg add bar
hg ci -m "First line of bar" bar
hg unshelve
pkill -INT shelveinterrupt如果您将此脚本作为
bash shelveinterrupt.sh,它会以
file 'foo' was deleted in local [working-copy] but was modified in other [shelve].
You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
What do you want to do? 它是脚本末尾的hg unshelve命令的响应。
我想打断一下这个提示。最后一个pkill的目的是中断shell进程,但当然不会在脚本等待输入时调用它。有没有一种不创建第二个脚本来调用第一个脚本的方法来调用这个脚本?
请注意,在中断脚本之后,您将得到
未解决的冲突(请参阅“hg解决”,然后“hg取消搁置-继续”)
发布于 2021-05-07 13:01:15
原来我想要做的事情可以用Tcl扩展来完成,expect。但是,这需要两个脚本。
一个外壳脚本。
#################################
shelveinterrupt.sh
#################################
#!/bin/bash
rm -rf test-shelveinterrupt
hg init test-shelveinterrupt
cd test-shelveinterrupt
hg branch foo
echo "First line of foo" >> foo
hg add foo
hg ci -m "First line of foo" foo
echo "Second line of foo" >> foo
hg shelve
hg up null
hg branch bar
echo "First line of bar" >> bar
hg add bar
hg ci -m "First line of bar" bar
hg log -vG
hg branch
hg unshelve还有一个期待的剧本。
#################################
shelveinterrupt.exp
#################################
#!/usr/bin/expect -f
spawn ./shelveinterrupt.sh
expect "What do you want to do?"
send -- "^C"
expect eof
# Check `hg status
cd test-shelveinterrupt
set hgst [exec hg status]
puts $hgst
exec hg update .这将产生以下输出
faheem@orwell:~/test-mercurial$ ./shelveinterrupt.exp
spawn ./shelveinterrupt.sh
marked working directory as branch foo
(branches are permanent and global, did you want a bookmark?)
shelved as foo
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
marked working directory as branch bar
unshelving change 'foo'
rebasing shelved changes
file 'foo' was deleted in local [working-copy] but was modified in other [shelve].
You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
What do you want to do? interrupted!
# The repository is in an unfinished *update* state.
# Unresolved merge conflicts:
#
# foo
#
# To mark files as resolved: hg resolve --mark FILE
# To continue: hg update .
abort: outstanding merge conflicts
(use 'hg resolve' to resolve)
while executing
"exec hg update ."
(file "./shelveinterrupt.exp" line 11)所以hg update .也不起作用。
https://unix.stackexchange.com/questions/647129
复制相似问题