0

I have no shell scripting experience. I want to create a shell script that will fetch changes from GIT and commit these changes to the SVN repository.

After searching a lot online and reading this link: Shell script to check git for changes and then loop through changed files?

i could come up with the following...

#!/bin/sh

#checks if there are any changes
if ! git --git-dir="/dir/.git" diff --quiet
then
    # do stuff...
    git --git-dir="/dir/.git" diff-tree ORIG_HEAD.. | \
    while read srcmode dstmode srcsha dstsha status srcfile dstfile
    do
        # do something with $srcfile and $dstfile
    done
fi

I guess the above will get changes from the GIT repo. Am I on the right path here? And now in the loop I want to commit the changes obtained from GIT.

How can this be done ?

I will be adding this script in Jenkins and it will execute as a post-build action.

Community
  • 1
  • 1
user1771680
  • 281
  • 1
  • 4
  • 17

1 Answers1

0

You'll want to use git-svn as Ju Liu suggested. Let's say you have the following setup:

  • Git repository at /repos/project.git.
  • Standard branches, tags, trunk directory structure at http://svn/project.

To copy commits from the git repository to the project Subversion trunk:

  1. Create a Git repository from Subversion:

    cd /repos
    git svn clone --stdlayout --revision 1:HEAD --no-minimize-url http://svn/project
    
  2. Add the git repository as a remote:

    cd project
    git remote add /repos/project.git
    
  3. Get the git commits you want. You can for example git pull and then git rebase [commit-id-of-the-subversion-head] to remove unwanted commits, or use git cherry-pick to get only some of them in the first place.

  4. When you have the commits you want, git svn dcommit to commit to Subversion.

You can keep both git repositories, and just update /repos/project with git svn rebase before doing additional pulls or cherry-picks from /repos/project.git.

Community
  • 1
  • 1
l0b0
  • 55,365
  • 30
  • 138
  • 223
  • Thanks :) this approach definitely looks a lot more easy. But if I had to write a shell script for it, would it be easy to write one ? – user1771680 Jun 26 '13 at 07:39
  • Probably not very difficult (the commands wouldn't be much more complicated than the ones above), but the real question is why you're copying commits and using two VCSes in the first place. – l0b0 Jun 26 '13 at 07:45