シェルスクリプトからプロンプトするには、Ctrl-Cを渡します。

シェルスクリプトからプロンプトするには、Ctrl-Cを渡します。

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シェルプロセスを中断するように設計されていますが、もちろんスクリプトが入力を待っている間は呼び出されません。最初のスクリプトを呼び出すために2番目のスクリプトを作成せずに呼び出す方法はありますか?

スクリプトを中断すると、次のメッセージが表示されます。

未解決の競合(「hg解決」を参照してから「hg unshelve --continue」を参照)

ベストアンサー1

私がやりたいことがTcl拡張を介して達成できることがわかり、それを期待しています。ただし、これには2つのスクリプトが必要です。

シェルスクリプト。

#################################
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

Expectスクリプトもあります。

#################################
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 .それは動作しません。

おすすめ記事