viewmergeclearcasesnapshotibm-rational

ClearCase can't merge from a snapshot view


I am using IBM Rational Clear Case, I have a snapshot view, with some checked-out files. This view is about to be obsolete, and I need these checked-out files to be merge to a new version (New view).

My problem: I am using ClearCase Version Tree Browser (clearvtree.exe) to do my merge. I opened the Version Tree for one of the checked-out files, on the view to which I want to merge the file. Now when ever I try to select the checked out file: right click -> and select "Merge to" I get the following error: "The selected version is not accessible from this view".

Note that when doing the same procedure on Dynamic View it works fine.

I know I can copy these files manually, but I am trying to find a way to do this, using the ClearCase tools (such as the Merge Tool and off-course the Version Tree).


Solution

  • OK, I have written a script (Actually two - which might be merged to one) that do what I need: To automatically merge from a snapshot view into a dynamic view. I assume it will also work with any other combination - but dynamic to dynamic or dynamic to snapshot is already supported by the IBM ClearCase "Merge Manager" tool.

    First Scrip will find all checkouts and format them accordingly, while adding them to files.txt:

    @echo off
    REM ------------------------------- synopsis ----------------------------------
    REM This script creates a list of all checked out into files.txt under the 
    REM batch-file directory.
    REM files in the following format:
    REM \VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
    REM \VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
    REM \VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
    REM ------------------------------- synopsis ----------------------------------
    
    set source_view_path=C:\Snapshot\some-snapshot-john
    set currentDirectory=%~dp0
    set chekedOutOutputFile=%currentDirectory%find_co.txt
    set resultFile=%currentDirectory%files.txt
    
    @echo Getting checkouts of %source_view_path%
    @echo %currentDirectory%
    
    REM ---------------------------------------------------------------------------
    REM The next code produces a find_co.txt intermediate file with the following 
    REM format of checkouts:
    REM <File Full Path>@@<Version ID>@@<File Comment>
    REM    %n  - for file Name (With full path)
    REM    %Vn - for file Version ID.
    REM    %c  - for file Comment
    REM
    REM Example:
    REM C:\MY_VIEW_PATH\VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
    REM C:\MY_VIEW_PATH\VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
    REM C:\MY_VIEW_PATH\VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
    REM --------------------------------------------------------------------------- 
    pushd %source_view_path%
    cleartool lsco -cview -avobs -fmt "%%n@@%%Vn@@%%c" > "%chekedOutOutputFile%"
    popd
    
    del /q "%resultFile%"
    
    REM ---------------------------------------------------------------------------
    REM The following code formats the find_co.txt into files.txt with the desired 
    REM result - <File VOB Path>@@<Version ID>@@<File Comment>
    REM Example:
    REM From -
    REM C:\MY_VIEW_PATH\VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
    REM C:\MY_VIEW_PATH\VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
    REM C:\MY_VIEW_PATH\VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
    REM To 
    REM \VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
    REM \VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
    REM \VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
    REM ---------------------------------------------------------------------------
    for /F "usebackq tokens=*" %%A in ("%chekedOutOutputFile%") do (
        call ::removeSourceViewPath "%%%A"
    )
    goto endOfScript
    
    REM ---------------------------------------------------------------------------
    REM Manipulate the path of each file to exclude the view from it e.g:
    REM C:\MY_VIEW_PATH\MY_VOB\file.txt -> \MY_VOB\file.txt
    REM >>>-----------------> start of :removeSourceViewPath 
    :removeSourceViewPath
        set str=%1
        call set "resultStr=%%str:%source_view_path%=%%"
        set resultStr=%resultStr:~1,-1%
        @echo %resultStr%
        @echo.%resultStr%>>"%resultFile%"
        exit /b
    
    REM <<<-----------------< end of :removeSourceViewPath
    REM ---------------------------------------------------------------------------
    
    :endOfScript
    
    pause
    @echo ------------------------------------------------------------------
    

    The second script takes the files.txt and merges them from a source view to a target view:

    @echo off
    REM ------------------------------- synopsis ----------------------------------
    REM This script takes a list of all files from the files.txt which is under 
    REM this batch-file directory and merges them from TARGET to SOURCES views
    REM files in the following format:
    REM <File VOB Path>@@<Version ID>@@<File Comment>
    REM are merged from <SOURCE_VIEW>\<File VOB Path> to 
    REM <TARGET_VIEW>\<File VOB Path> with the <File Comment> as comment.
    REM ------------------------------- synopsis ----------------------------------
    setlocal
    
    set TARGET_VIEW=V:\v11-john-local-nt
    set SOURCE_VIEW=C:\Snapshot\some-snapshot-john
    
    REM ---------------------------------------------------------------------------
    REM The following takes the line:
    REM <File VOB Path>@@<Version ID>@@<File Comment> and checks out the target 
    REM file, then it automatically merges the file from source to target.
    REM Note that the version is not required here (it might be required if we
    REM want to merged from a version which is not the latest one in the branch).
    REM ---------------------------------------------------------------------------
    for /f "tokens=1,2,3 delims=@@" %%i in (files.txt) do (
        cleartool co -unreserved -c "%%k" %TARGET_VIEW%%%i
        cleartool merge -to %TARGET_VIEW%%%i %SOURCE_VIEW%%%i 
    )
    
    endlocal
    
    pause
    

    Both of this scripts merged all the file I needed from the source View to the target View.

    Notes: