{"thread":{"id":"19026","subject":"How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","startedAt":"2009-04-23T18:59:20Z","lastAt":"2009-05-07T21:34:42Z","messageCount":5,"participants":["ask4thunder","David Aguilar","Peter Baumann","Charles O'Farrell","Chris Packham"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"112112","messageId":"23197522.post@talk.nabble.com","threadId":"19026","inReplyTo":null,"subject":"How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","fromName":"ask4thunder","fromEmail":"ask4thunder@gmail.com","sentAt":"2009-04-23T18:59:20Z","receivedAt":"2009-04-23T18:59:20Z","isPatch":false,"sender":{"key":"ask4thunder@gmail.com","avatar":null},"body":"\nHi Everyone, \n\nThanks for looking into this thread.\n\nThis is a help on GIT to ClearCase sync and am using UNIX session and not\nWindows\n\nI am intending to use ClearCase in the background and GIT in the front.\nFor syncing files from ClearCase to GIT i \ncheckout the git branch\nuse rsync command to get the changed files in ClearCase\nand then i do the 'git add' and 'git commit'\n\nThis works out well, but i want to get a list of files changed in GIt so\nthat i can bring that to ClearCase and checkout and checkin files.\n\nCan someone provide me the commands to\n\n1. Get list of files changed in GIT, after i do commit?\n2. Get list of files changed in GIT after commit, but files changed after a\ntag (baseline).\n3. Sync these files to ClearCase?\n\n\nHope you gurus can help me....am in desperate need of these commands. \nAppreciate your help  in this.\n\nThanks\nask4thunder\n\n-- \nView this message in context: http://www.nabble.com/How-to-sync-changes-in-GIT-to-ClearCase-or-How-to-get-the-list-of-files-changed-in-GIT-for-a-specific-branch-tp23197522p23197522.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"112155","messageId":"20090424043114.GC15612@gmail.com","threadId":"19026","inReplyTo":"23197522.post@talk.nabble.com","subject":"Re: How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-24T04:31:15Z","receivedAt":"2009-04-24T04:31:15Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On  0, ask4thunder <ask4thunder@gmail.com> wrote:\n> \n> I am intending to use ClearCase in the background and GIT in the front.\n> For syncing files from ClearCase to GIT i \n> checkout the git branch\n> use rsync command to get the changed files in ClearCase\n> and then i do the 'git add' and 'git commit'\n\nTo handle files that have been removed make sure to use\n\trsync --exclude=.git --delete ...\n\nand\n\tgit add -u\n\nto remove any deleted files from git.\n\n\n> This works out well, but i want to get a list of files changed in GIt so\n> that i can bring that to ClearCase and checkout and checkin files.\n> \n> Can someone provide me the commands to\n> \n> 1. Get list of files changed in GIT, after i do commit?\n\n\nOne possibility:\n\nmove to the root of the clearcase project\n\nset GIT_DIR to point to the .git directory\n(which, presumably is outside the clearcase project)\n\nand some combination of:\n\tgit diff --name-only\n\tgit diff-index --name-status HEAD\n\nIf clearcase wasn't so painful you would ideally just\nrun 'git checkout -f' to make clearcase match git,\nbut clearcase is horrible and you have to explicitly\n'clearcase checkout' each file.\n\n\n> 2. Get list of files changed in GIT after commit, but files changed after a\n> tag (baseline).\n\n\tgit diff --name-only <the-commit>^!\n\n\tgit diff --name-only <the-tag>..HEAD\n\n(or diff-index, etc)\n\n\n> 3. Sync these files to ClearCase?\n\n\tclearcase checkout the <path>\n\tgit checkout HEAD -- <path>\n\n\t(assuming you've set GIT_DIR accordingly\n\t and are sitting at the root of the project)\n\n\n> Hope you gurus can help me....am in desperate need of these commands. \n> Appreciate your help  in this.\n\nIf you get this stuff working with native clearcase commands,\nthen others could benefit from your work.\n\nbi-directional git<->cc can be tricky (and importing all of\nbranches can be even trickier), but even being able to import\none branch is better than nothing, no?\n\nThe reason I replied is that I, too, once wrote a similar\ntool to suck cc projects into git.  One project\nwas so huge (and cc sucks so bad) that it\nliterally took a few weeks for it to import.\n\nOur organization also ran vob backups at 2am everynight,\nso I couldn't just let it run continuously since clearcase\nwould lock the script out at 2am.\n\nIt ran incrementally, and lots of other site-specific\nhacks.  I don't know clearcase at all (our site used a bunch\nof in-house wrapper commands) so I never bothered to make\nit work with raw cc commands. That's why I have nothing\nto share.  It was also a total hack and once I got the stuff\nI wanted out of it, you can bet that I never looked back\n(which is why the bi-directional part was not important\n to me at all).\n\n\nclearcase.. wow <shudders>\n\nAll it does is remind me of this horrible, horrible cc mvfs\nkernel module bug that was going around deleting automounts...\n\nokay.. enough scary thoughts.\n\n\nkudos for fighting the good fight,\n\n-- \n\n\tDavid\n"},{"id":"112171","messageId":"20090424092007.GD25300@m62s10.vlinux.de","threadId":"19026","inReplyTo":"23197522.post@talk.nabble.com","subject":"Re: How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","fromName":"Peter Baumann","fromEmail":"waste.manager@gmx.de","sentAt":"2009-04-24T09:20:07Z","receivedAt":"2009-04-24T09:20:07Z","isPatch":false,"sender":{"key":"waste.manager@gmx.de","avatar":null},"body":"On Thu, Apr 23, 2009 at 11:59:20AM -0700, ask4thunder wrote:\n> \n> Hi Everyone, \n> \n> Thanks for looking into this thread.\n> \n> This is a help on GIT to ClearCase sync and am using UNIX session and not\n> Windows\n> \n> I am intending to use ClearCase in the background and GIT in the front.\n> For syncing files from ClearCase to GIT i \n> checkout the git branch\n> use rsync command to get the changed files in ClearCase\n> and then i do the 'git add' and 'git commit'\n> \n> This works out well, but i want to get a list of files changed in GIt so\n> that i can bring that to ClearCase and checkout and checkin files.\n> \n> Can someone provide me the commands to\n> \n> 1. Get list of files changed in GIT, after i do commit?\n> 2. Get list of files changed in GIT after commit, but files changed after a\n> tag (baseline).\n> 3. Sync these files to ClearCase?\n> \n> \n> Hope you gurus can help me....am in desperate need of these commands. \n> Appreciate your help  in this.\n> \n> Thanks\n> ask4thunder\n> \n\nThis is what I used to work with clearcase in a former job:\n\nUse cc_import.sh to import your changes and later export your changes\nback to CC with export2cc.pl <path_to_CC_repo> <LABEL> <from> <to>\n\nGreetings,\nPeter\n\n\ncc_import.sh: Importing files from the clearcase checkout\n\n#!/bin/sh\n\n# ATTENTION: This will create a branch named 'cc' in your git import\n# Make sure that your actual checkout is NEVER on that branch if\n# running this script!!!!\n\n\n###########################\n# Adapt this to your needs\n\nBRANCH=refs/heads/cc\n\nexport GIT_WORK_TREE=\"/place/where/your/clearcase/checkout/is\"\nMY_GIT_IMPORT=\"/place/to/your/git-import\"\n\n###########################\n\n\n\nexport GIT_INDEX_FILE=\"${MY_GIT_IMPORT}/.git/index.clearcase\"\n\n# save your HEAD\ncp .git/HEAD .git/HEAD.local\n\n# switch to the clearcase import branch\ngit symbolic-ref HEAD \"$BRANCH\"\n\ngit add -u\ngit add .\n\n\n# use the date of the checkin as commit message\ndatum=$(date +'%Y.%m.%d %T')\ngit commit -m\"$datum\"\n\n# switch HEAD back to your previous one\ncp .git/HEAD.local .git/HEAD\n\n\n========================\n\nexport2cc.pl: exporting git revisions to CC\n\n#!/usr/bin/perl\n\n# TODO's:\n#  - The commit msg might be extracted multiple times\n#  - it has a hardcoded path name (right now: /d/msg)\n#  - There is a proplem adding a deep hierarchy of files\n#    (e.g. newdir1/newdir2/newfile1}\n#  - No rename support\n\n\nuse File::Basename;\nuse strict;\n\nmy $verbose = 1;\nmy $upstream;\nmy $from;\n\nmy $cc_repo;\nmy $CC_LABEL;\n\n$cc_repo = shift @ARGV;\n$CC_LABEL = shift @ARGV;\n\nprint \"CC repo: $cc_repo\\n\";\nprint \"Label:   $cc_repo\\n\";\n\nsub run_cmd_pipe {\n\tif ($^O eq 'MSWin32' || $^O eq 'msys') {\n\t\tmy @invalid = grep {m/[\":*]/} @_;\n\t\tdie \"$^O does not support: @invalid\\n\" if @invalid;\n\t\tmy @args = map { m/ /o ? \"\\\"$_\\\"\": $_ } @_;\n\t\treturn qx{@args};\n\t} else {\n\t\tmy $fh = undef;\n\t\topen($fh, '-|', @_) or die;\n\t\treturn <$fh>;\n\t}\n}\n\nif (scalar(@ARGV) >= 1) {\n\t$upstream = $ARGV[0];\n\n\t$from = ((scalar(@ARGV) >= 2) ? \"$ARGV[1]\" : \"HEAD\");\n}\n\n\nmy @revisions;\npush @revisions, \"$ARGV[0]\";\n\ndoit($revisions[0]);\n\nsub doit($) {\n\tmy $rev = shift;\n\n\tmy @difftree_result = qx(git diff-tree -r --name-status $rev^ $rev -- );\n\n\tmy @added_files;\t# A\n\tmy @copied_files;\t# C\n\tmy @deleted_files;\t# D\n\tmy @renamed_files;\t# R\n\n\tmy @modified_files;\t# M\n\n\tforeach (@difftree_result) {\n\t\tmy ($status, $file) = split /\\t/;\n\t\tchomp $file;\n\n\n\t\tif ($status =~ /A/) {\n\t\t\tprint \"adding file \\'$file\\'\\n\" if ($verbose);\n\t\t\tpush @added_files, \"$file\";\n\t\t}\n\n\t\tif ($status =~ /C/) {\n\t\t\tprint \"copied file '$file'\\n\" if ($verbose);\n\t\t\tpush @copied_files, \"$file\";\n\t\t}\n\n\t\tif ($status =~ /D/) {\n\t\t\tprint \"deleted file '$file'\\n\" if ($verbose);\n\t\t\tpush @deleted_files, \"$file\";\n\t\t}\n\n\t\tif ($status =~ /R/) {\n\t\t\tprint \"renamed file '$file'\\n\" if ($verbose);\n\t\t\tpush @renamed_files, \"$file\";\n\t\t}\n\n\t\tif ($status =~ /M/) {\n\t\t\tprint \"modify file '$file'\\n\" if ($verbose);\n\t\t\tpush @modified_files, \"$file\";\n\t\t}\n\t}\n\n\t# sort the files\n\t@added_files   = sort @added_files;\n\t@copied_files  = sort @copied_files;\n\t@deleted_files = sort @deleted_files;\n\t@renamed_files = sort @renamed_files;\n\t@modified_files= sort @modified_files;\n\n\tmy $commit_msg = extract_commitmsg_from_git($rev);\n\tprint $commit_msg;\n\n\tforeach (@renamed_files, @copied_files) {\n\t\tprint \"- $_\" . \"\\n\";\n\t\tdie \"can't handle renames\";\n\t}\n\n\n\tforeach (@deleted_files) {\n\t\tmy ($filename, $dirname) = fileparse($_);\n\n\t\tdie \"The directory $cc_repo/$dirname doesn't exist\" if (! -d \"$cc_repo/$dirname\");\n\n\t\tcc_checkout($cc_repo, $dirname, \"\") || die \"Can't checkout $dirname\\n\";\n\t\tcc_rmname($cc_repo, $_, $commit_msg) || die \"Can't delete $_\\n\";\n\t\tcc_checkin($cc_repo, $dirname, \"\") || die \"Can't checkin $dirname\\n\";\n\n\t\t# lable file and directory\n\t\tcc_mklabel($cc_repo, $dirname, $CC_LABEL) || die \"Can't label $_\\n\";\n\t}\n\t\n\tforeach (@added_files) {\n\t\tprint \"N $_\" . \"\\t(add the file manually)\\n\";\n\t\t\n\t\tmy ($filename, $dirname) = fileparse($_);\n\n\t\tdie \"The directory $cc_repo/$dirname doesn't exist\" if (! -d \"$cc_repo/$dirname\");\n\n\t\tcc_checkout($cc_repo, $dirname, \"\") || die \"Can't checkout $dirname\\n\";\n\t\textract_file_from_git($cc_repo, $_, $rev);\n\t\tcc_mkelem($cc_repo, $_, $commit_msg);\n\t\tcc_checkin($cc_repo, $_, \"\") || die \"Can't checkin $_\\n\";\n\t\tcc_checkin($cc_repo, $dirname, \"\") || die \"Can't checkin $dirname\\n\";\n\n\t\t# lable file and directory\n\t\tcc_mklabel($cc_repo, $_, $CC_LABEL) || die \"Can't label $_\\n\";\n\t\tcc_mklabel($cc_repo, $dirname, $CC_LABEL) || die \"Can't label $_\\n\";\n\t}\n\n\tforeach (@modified_files) {\n\t\tprint \"M $_\" . \"\\n\";\n\t\tcc_checkout($cc_repo, $_, $commit_msg) || die \"Can't checkout $_\\n\";\n\t\textract_file_from_git($cc_repo, $_, $rev);\n\t\tcc_checkin($cc_repo, $_, $commit_msg) || die \"Can't checkin $_\\n\";\n\t\tcc_mklabel($cc_repo, $_, $CC_LABEL);\n\t}\n}\n\n\n\nsub cc_checkout ($$$) {\n\tmy $path_to_repo = shift;\n\tmy $file = shift;\n\tmy $commit_msg = shift;\n\n\tmy $result;\n\tmy $errcode = 0;\n\n\tif ($commit_msg eq \"\") {\n\t\t$result = qx(cleartool co -res -ncomment \"$path_to_repo/$file\");\n\t\t$errcode = ($? >> 8);\n\t} else {\n\t\tmy $msg_file = \"/d/msg.txt\";\n\t\topen(MSGFILE, \">$msg_file\")\n\t\t\tor die \"can't export the commit msg\";\n\t\n\t\tprint MSGFILE $commit_msg;\n\t\tclose(MSGFILE);\n\t\n\t\t#print \"cleartool co -res -unr -cfi $msg_file $path_to_repo/$file\\n\";\n\t\t$result = qx(cleartool co -res -unr -cfi $msg_file \"$path_to_repo/$file\");\n\t\t$errcode = ($? >> 8);\n\t\n\t\tqx(rm $msg_file);\n\t}\n\n\tprint $result;\n\treturn !$errcode;\n}\n\nsub cc_checkin ($$$) {\n\tmy $path_to_repo = shift;\n\tmy $file = shift;\n\tmy $commit_msg = shift;\n\n\tmy $result;\n\tmy $errcode = 0;\n\n\tif ($commit_msg eq \"\") {\n\t\t$result = qx(cleartool ci -nc \"$path_to_repo/$file\");\n\t\t$errcode = ($? >> 8);\n\t} else {\n\t\tmy $msg_file = \"/d/msg.txt\";\n\t\topen(MSGFILE, \">$msg_file\")\n\t\t\tor die \"can't export the commit msg\";\n\n\t\tprint MSGFILE $commit_msg;\n\t\tclose(MSGFILE);\n\n\t\t$result = qx(cleartool ci -cfi $msg_file \"$path_to_repo/$file\");\n\t\t$errcode = ($? >> 8);\n\n\t\tqx(rm $msg_file);\n\t}\n\n\tprint $result;\n\n\treturn !$errcode;\n}\n\n##\n# Add a new file/directory to clearcase\n#\n# @preconditon: the underlying directory is already checked out\nsub cc_mkelem($$$) {\n\tmy $path_to_repo = shift;\n\tmy $file = shift;\n\tmy $commit_msg = shift;\n\n\tmy $msg_file = \"/d/msg.txt\";\n\topen(MSGFILE, \">$msg_file\")\n\t\tor die \"can't export the commit msg\";\n\n\tprint MSGFILE $commit_msg;\n\tclose(MSGFILE);\n\n\tmy $result = qx(cleartool mkelem -cfi $msg_file \"$path_to_repo/$file\");\n\tdie \"mkelem $path_to_repo/$file failed\" if ($?);\n\t\n\tprint $result;\n\n\tqx(rm $msg_file);\n}\n\n##\n# Delete a file from clearcase\n#\n# @precondition: the underlying directory is already checked out\nsub cc_rmname($$$) {\n\tmy $path_to_repo = shift;\n\tmy $file = shift;\n\tmy $commit_msg = shift;\n\n\tmy $errcode = 0;\n\n\tmy $msg_file = \"/d/msg.txt\";\n\topen(MSGFILE, \">$msg_file\")\n\t\tor die \"can't export the commit msg\";\n\n\tprint MSGFILE $commit_msg;\n\tclose(MSGFILE);\n\n\tmy $result = qx(cleartool rmname -f -cfi $msg_file \"$path_to_repo/$file\");\n\tdie \"rmname $path_to_repo/$file failed\" if ($?);\n\t$errcode = ($? >> 8);\n\t\n\tprint $result;\n\n\tqx(rm $msg_file);\n\treturn !$errcode;\n}\n\n##\n#\nsub cc_mklabel($$$) {\n\tmy $path_to_repo = shift;\n\tmy $file = shift;\n\tmy $label = shift;\n\t\n\tmy $result = qx(cleartool mklabel -replace \"$label\" \"$path_to_repo/$file\");\n\tdie \"mklabel $path_to_repo/$file failed\" if ($?);\n\tprint $result;\n}\n\nsub extract_file_from_git($$$) {\n\tmy $cc_repo_path = shift;\n\tmy $file = shift;\n\tmy $rev = shift;\n\n\tmy $result = qx(git show $rev:$file > $cc_repo_path/$file);\n\tdie \"extract_file_from_git $cc_repo_path/$file failed\" if ($?);\n}\n\nsub extract_commitmsg_from_git($) {\n\tmy $revision = shift;\n\n\tmy $result = qx(git log -1 --pretty=format:'%s%n%b' $revision --);\n\tdie \"extract_commitmsg_from_git $revision failed\" if ($?);\n\treturn $result;\n}\n"},{"id":"112176","messageId":"loom.20090424T120653-407@post.gmane.org","threadId":"19026","inReplyTo":"23197522.post@talk.nabble.com","subject":"Re: How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","fromName":"Charles O'Farrell","fromEmail":"charleso@charleso.org","sentAt":"2009-04-24T12:10:58Z","receivedAt":"2009-04-24T12:10:58Z","isPatch":false,"sender":{"key":"charleso@charleso.org","avatar":"https://gravatar.com/avatar/ce96d531daa37646a38a81e48113865af86a6d290ad92931f3b217896bdf86ea?d=mp&s=160"},"body":"A Clearcase/Git bridge I wrote for my current job. It also pulls in history as\nbest it can.\n\nhttp://github.com/charleso/git-cc/tree/master\n\nCharles\n"},{"id":"113267","messageId":"a038bef50905071434v59354824i8112f32e8359c726@mail.gmail.com","threadId":"19026","inReplyTo":"41a31a5a0905071204s597cb76ek524748b8b919b25e@mail.gmail.com","subject":"Re: How to sync changes in GIT to ClearCase or How to get the list of files changed in GIT for a specific branch","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2009-05-07T21:34:42Z","receivedAt":"2009-05-07T21:34:42Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On Fri, May 8, 2009 at 7:04 AM, Senthil Kumar <ask4thunder@gmail.com> wrote:\n> Hey Chris,\n>\n> First thanks for giving me the knowledge transfer and i really appreciate\n> it. Am working on the sync stuff now, but i have an issue in a perl script\n> in post-update hook.\n>\n>  Have a doubt here, am writing a post-update hook in perl, so that whenever\n> a user pushes code from their local repo to the bare public repo, the\n> post-update hook triggers so as to pull changes from the abre public repo to\n> the actual parent data repo.\n>\n> My data repo: /snaps4/searumugam/spec-repo/mydodo.repo\n> My bare repo: /snaps4/searumugam/spec-repo/mydodo.bare\n> My local repo: /snaps4/searumugam/githome/searumugam_mydodo\n>\n> here is what i have in the script (left),  and the output i get is in blue\n> (right)\n>\n> The concept: First when a user pushes to bare repo -\n> /snaps4/searumugam/spec-repo/mydodo.bare, the post-update trigger starts, it\n> shd cd into the data repo path  (/snaps4/searumugam/spec-repo/mydodo.repo)\n> and initiate a 'git pull'\n>\n> The $data path has the correct path - my data repo path, where the pull will\n> be initiated,\n>\n> print \"\\nData Path: $data_path\\n\";                 Data Path:\n> /snaps4/searumugam/spec-repo/mydodo.repo/\n> chdir ($data_path);\n> system(\"pwd\");\n> /snaps4/searumugam/spec-repo/mydodo.repo\n> system(\"git pull\");                                      fatal: Not a git\n> repository: '.'\n> system(\"pwd\");\n> /snaps4/searumugam/spec-repo/mydodo.repo\n>\n> i even tried with system(\"/usr/libexec/git-core/git-pull\"); but its saying\n> the same error. But when i do it manually in the same direcotory it works\n>\n> Manual pull, when am in the same directory.\n> rndhyper1:/snaps4/searumugam/spec-repo/mydodo.repo 30> pwd\n> /snaps4/searumugam/spec-repo/mydodo.repo\n> rndhyper1:/snaps4/searumugam/spec-repo/mydodo.repo 31> git pull\n> remote: Counting objects: 5, done.\n> remote: Compressing objects: 100% (4/4), done.\n> remote: Total 4 (delta 2), reused 0 (delta 0)\n> Unpacking objects: 100% (4/4), done.\n> From /snaps4/searumugam/spec-repo/mydodo.bare\n>    cb9f659..2c5bca8  master     -> origin/master\n> Updating cb9f659..2c5bca8\n> Fast forward\n>  0 files changed, 0 insertions(+), 0 deletions(-)\n>  create mode 100644 final111223\n>  create mode 100644 final1112233\n>\n> Am i doing something wrong, or should i execute 'git pull' in a different\n> manner?\n> hope you could help mein this.\n>\n> Thanks & Regards\n> Senthil A Kumar\n>\n\nLike I say not exactly an expert. But it looks like when run in this\nmanner 'git pull' is unable to figure out the location of the .git\ndirectory. Try something like.\n\nsystem(\"GIT_DIR=$data_path.git; git pull\");\n\nThere were some other replies to your original post that promising for\nthe cc-to-git-and-back aspect. Looking into them may save you a lot of\ntime.\n\nGood luck.\n"}]}