Toward an ideal workflow with ClearCase and Git

社会主义新天地 提交于 2019-11-30 15:51:38
nowox

A possible solution from VonC

In VonC's answer, he suggests to not use an intermediate branch and manage everything with Git.

Through an example I would like to show his method. We start with this configuration on ClearCase:

  o------o----o (develop)
 /        \ 
*----------o (main)

The idea is to use Git to facilitate the development of a new feature that will eventually be merged to the develop branch.

We first copy the ClearCase project into a local folder and init a Git repository (in the case the Git repository doesn't already exist).

WORKSPACE=~/foo
cp `cleartool ls -r | grep '@@' | sed 's/@@.*$//'` $WORKSPACE
cd $WORKSPACE
git init
git add .
git commit -m "Initial commit"
git checkout -b feature

We spend some time developing the feature on its own local Git branch:

                  x----x--x---x----x (feature on Git)
                 /
                x---------- (master on Git)
               /
  o------o----o------o----o (develop)
 /        \ 
*----------o (main)

At the end of the day it is time to sync-down the possible changes from ClearCase:

git checkout master
git --ls-files | xargs rm
cd $CCVIEW
cleartool ls -r | grep '@@' | sed 's/@@.*$//' > $WORKSPACE/ccview
cd $WORKSPACE
cat ccview | xargs -n1 cp {} $WORKSPACE    
cat ccview | xargs git add 
git commit -m "Imported from CC"

So now we have made several commit on the feature branch and the master Git branch was synchronized with ClearCase.

                  x----x--x---x----x (feature on Git)
                 /
                x-----------o (master on Git)
               /           /
  o------o----o------o----o (develop)
 /        \ 
*----------o (main)

We must not to forget to lock the ClearCase View during the entire merge process. This is required to prevent other developers to see their own changes erased by clearfsimport. To lock a ClearCase branch it is easy:

cleartool lock brtype:$BR_NAME 

Then the merge can be done on Git:

git checkout master
git merge feature

The feature Git branch was merged with the master.

                  x----x--x---x----x (feature on Git)
                 /                  \
                x-----------o--------o (master on Git)
               /           /
  o------o----o------o----o (develop)
 /        \ 
*----------o (main)

The modifications can be pushed back to ClearCase

OUT="$(mktemp -d)"
cp -v --parents `git ls-files | sed 's/[^ ]*\.gitignore//g'` $OUT
clearfsimport -comment 'clearfsimport' -rec -unco -nset $OUT $CVIEW    
rm -rf $OUT

And the lock can be removed to re-authorize the changes on the branch

cleartool unlock brtype:$BR_NAME

.

                  x----x--x---x----x (feature on Git)
                 /                  \
                x-----------o--------o (master on Git)
               /           /          \
  o------o----o------o----o------------o (develop)
 /        \ 
*----------o (main)

The Git repository and the local workspace may be removed unless we need to go on.

  o------o----o------o----o------------o (develop)
 /        \ 
*----------o (main)

In this solution, we did not use an intermediate branch on ClearCase and all the merge process occurred on Git. The ClearCase history is preserved. The only bad point is the need to lock the development branch for the final merge.

@VonC, feel free to modify my answer if I am wrong.

Actually, what I call a feature could be also a simple refactoring, such as a massive renaming inside the project. In this example, and because ClearCase is file-centric, we always need a temporary branch (no atomic checkin in non-UCM CC).
Creating a new branch is painful and having the right config-spec is a struggling task

So... don't create a temporary branch?
If this is to be used in collaboration with Git, only create that feature branch in the Git repo, do the final merge in the Git Repo, and then clearfsimport the result in the main ClearCase view.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!