その他
    ホーム 技術発信 DoRuby svn moveを試してみる

    svn moveを試してみる

    この記事はアピリッツの技術ブログ「DoRuby」から移行した記事です。情報が古い可能性がありますのでご注意ください。

    ブランチをトランクにするために、svn moveをローカルで検証してみました。

     svn moveって何?

    svn moveコマンドは、作業コピーやリポジトリにある、ファイルやディレクトリを移動することができます。

    ※内部的には、svn copyの後にsvn deleteを行っている模様

    ※以下の手順のパス等は、Mac環境のものです。

     事前準備(検証用のデータを作成)

    リポジトリ作成

    $ cd
    $ mkdir -p Documents/svn/repos
    $ svnadmin create Documents/svn/repos
    $ svn mkdir file://localhost/Users/hoge/Documents/svn/repos/trunk -m "create directory trunk"
    $ svn mkdir file://localhost/Users/hoge/Documents/svn/repos/branches -m "create directory branches"
    $ svn mkdir file://localhost/Users/hoge/Documents/svn/repos/tags -m "create directory tags"
    

    チェックアウト

    $ cd Documents/svn
    $ mkdir working-copy
    $ cd working-copy
    $ svn co file://localhost/Users/hoge/Documents/svn/repos/trunk
    

    コミット

    トランク見分けるためファイルをコミットします。

    $ cd trunk
    $ touch trunk.txt
    $ vim trunk.txt
    ---- ここから ----
    trunk!
    ---- ここまで ----
    $ svn add trunk.txt
    $ svn ci trunk.txt -m 'create trunk.txt'
    

    ブランチ作成(URL -> URL)

    $ svn copy file://localhost/Users/hoge/Documents/svn/repos/trunk file://localhost/Users/hoge/Documents/svn/repos/branches/branch -m 'create new branch'
    $ svn ls file://localhost/Users/hoge/Documents/svn/repos/branches
    branch/
    $ svn ls file://localhost/Users/hoge/Documents/svn/repos/branches/branch
    hoge.txt
    trunk.txt
    

    ブランチチェックアウト

    $ cd ../working-copy
    $ svn co file://localhost/Users/hoge/Documents/svn/repos/branches/branch
    A    branch/trunk.txt
    Checked out revision 5.
    

    ブランチを区別するコミット

    $ cd branch
    $ touch branch.txt
    $ vim branch.txt
    ---- ここから ----
    branch!
    ---- ここまで ----
    $ svn add branch.txt
    $ svn ci branch.txt -m 'create branch.txt'
    

     svn move検証

    いよいよ本題のsvn moveの検証です。

    ①branch -> tagsにコピー

    バックアップのためブランチをtagsにコピーします。

    $ svn copy file://localhost/Users/hoge/Documents/svn/repos/branches/branch file://localhost/Users/hoge/Documents/svn/repos/tags/branch_snapshot -m 'create tags branch_snapshot'
    $ cd ..
    $ svn co file://localhost/Users/hoge/Documents/svn/repos/tags/branch_snapshot
    $ cd branch_snapshot/
    $ ls
    branch.txt trunk.txt
    $ cat branch.txt
    branch!
    $ cat trunk.txt
    trunk!
    $ svn log
    ------------------------------------------------------------------------
    r7 | hoge | 2015-12-24 15:45:45 +0900 (水, 24 12 2015) | 1 line
    
    create tags branch_snapshot
    ------------------------------------------------------------------------
    〜省略〜
    →copy時点のbranchのファイルとリビジョン履歴がコピーできている。OK
    

    ②trunk -> tagsにmove

    バックアップのためトランクをtagsに移動します。

    $ svn move file://localhost/Users/hoge/Documents/svn/repos/trunk file://localhost/Users/hoge/Documents/svn/repos/tags/trunk_snapshot -m 'create tags trunk_snapshot'
    

    trunk-snapshotが出来ているか

    $ svn ls file://localhost/Users/hoge/Documents/svn/repos/tags/branch_snapshot/
    trunk_snapshot/
    →OK
    

    trunkが消えていること

    $ svn ls file://localhost/Users/hoge/Documents/svn/trunk
    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file://localhost/Users/hoge/Documents/svn/trunk'
    →OK
    

    trunk_snapshotをcoしてファイル(trunk.txtのみ)とリビジョン履歴確認

    $ cd ..
    $ svn co file://localhost/Users/hoge/Documents/svn/repos/tags/trunk_snapshot
    A    trunk_snapshot/trunk.txt
    Checked out revision 8.
    $ cat trunk_snapshot/trunk.txt
    trunk!
    $ svn log trunk_snapshot/
    ------------------------------------------------------------------------
    r8 | hoge | 2015-12-24 15:55:16 +0900 (水, 24 12 2015) | 1 line
    
    create tags trunk_snapshot
    ------------------------------------------------------------------------
    r4 | hoge | 2015-12-24 15:36:01 +0900 (水, 24 12 2015) | 1 line
    
    create trunk.txt
    ------------------------------------------------------------------------
    r1 | hoge | 2015-12-24 15:33:03 +0900 (水, 24 12 2015) | 1 line
    
    create directory trunk
    ------------------------------------------------------------------------
    →OK
    

    ③branch -> trunkにmove

    ブランチをトランクに移動します。

    $ svn move file://localhost/Users/hoge/Documents/svn/repos/branches/branch file://localhost/Users/hoge/Documents/svn/repos/trunk -m 'create trunk move branch'
    

    trunkが出来ているか

    $ svn ls file://localhost/Users/hoge/Documents/svn/repos/trunk
    branch.txt
    trunk.txt
    →OK
    

    branchが消えていること

    $ svn ls file://localhost/Users/hoge/Documents/svn/branches/branch
    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file://localhost/Users/hoge/Documents/svn/branches/branch'
    →OK
    

    trunkをcoしてファイル(trunk.txtとbranch.txt)とリビジョン履歴確認

    $ cd ~/Documents/svn/working-copy
    $ svn co file://localhost/Users/hoge/Documents/svn/repos/trunk trunk_moved
    $ cat trunk_moved/trunk.txt
    trunk!
    $ cat trunk_moved/branch.txt
    branch!
    $ svn log trunk_moved/
    ------------------------------------------------------------------------
    r9 | hoge | 2015-12-24 16:06:14 +0900 (水, 24 12 2015) | 1 line
    
    create trunk move branch
    ------------------------------------------------------------------------
    r6 | hoge | 2015-12-24 15:40:30 +0900 (水, 24 12 2015) | 1 line
    
    create branch.txt
    ------------------------------------------------------------------------
    r5 | hoge | 2015-12-24 15:36:56 +0900 (水, 24 12 2015) | 1 line
    
    create branch from trunk
    ------------------------------------------------------------------------
    r4 | hoge | 2015-12-24 15:36:01 +0900 (水, 24 12 2015) | 1 line
    
    create trunk.txt
    ------------------------------------------------------------------------
    r1 | hoge | 2015-12-24 15:33:03 +0900 (水, 24 12 2015) | 1 line
    
    create directory trunk
    ------------------------------------------------------------------------
    →OK
    

    ちゃんとブランチにコミットしたファイルが存在し、ログも問題なさそうですね。

    以上です。