後來寫了個建構環境和merge log的script:
建立該篇文章的環境:
用法:
$ bash create_env.sh /home/svn/ #在 /home/svn/ 下建立test和test2的repos,並建立那篇文章的資料結構
#!/bin/bash # $ bash create_env.sh# eg. # bash create_env.sh /home/svn/ SVN_REPOS_PATH=$1 cd ${SVN_REPOS_PATH} svnadmin create test svnadmin create test2 # cook test repos svn checkout file://${SVN_REPOS_PATH}test test_checkout cd test_checkout mkdir trunk tags branches touch trunk/hello.txt svn add * svn commit -m "hello test" svn update svn log cd .. # cook test2 repos svn checkout file://${SVN_REPOS_PATH}test2 test2_checkout cd test2_checkout mkdir trunk tags branches mkdir -p trunk/media/cloud/web/internet svn add * svn commit -m "hello test2" svn update svn log cd .. rm -rf test_checkout test2_checkout ls -l
merge log:
用法:
# bash test_merge_log.sh /home/svn/test /home/svn/test2 trunk/media/cloud/web/internet # 把test的log搬到test2的 trunk/media/cloud/web/internet 資料夾下
#!/bin/bash # merge REPOS1 log to REPOS2 folder # run it as root # # bash test_merge_log.sh# eg. # bash test_merge_log.sh /home/svn/test /home/svn/test2 trunk/media/cloud/web/internet SVN_REPOS1_PATH=$1 SVN_REPOS2_PATH=$2 REPOS2_FOLDER=$3 svnadmin dump ${SVN_REPOS1_PATH} > test.dump cat test.dump | svndumpfilter include "trunk" --drop-empty-revs --renumber-revs > test_trunk.dump find . -name test_trunk.dump | xargs perl -ne 'open NEW, ">>test_trunk_new.dump"; s/trunk\///g; print NEW' svnadmin load ${SVN_REPOS2_PATH} --parent-dir ${REPOS2_FOLDER} --ignore-uuid < test_trunk_new.dump rm *.dump # check svn checkout file://${SVN_REPOS2_PATH} test2_checkout cd test2_checkout svn log cd .. rm -rf test2_checkout
原始碼:
https://github.com/kalecgos0616/tools/tree/master/svn
注意:
要在該tty 也cd到資料夾要用 . xxx.sh (要多一個點),否則用bash xxx.sh不會換目錄,但仍然會在該目錄執行指令
The reason is that each process has its own current directory, and when you execute a program from the shell it is run in a new process. The standard "cd", "pushd" and "popd" are builtin to the shell interpreter so that they affect the shell process.
翻譯:
每個process 擁有自己的資料夾,當你執行一個shell程式時等於開了一個新的process。"cd"那些指令被內置到shell解釋器,仍影響shell進程。使用source(.) 會讓該process在現在的tty環境執行
參考資料:
http://stackoverflow.com/questions/874452/change-current-directory-from-a-script
沒有留言:
張貼留言