lacton
lacton

Reputation: 2366

Maintain a patched open source library in Git

Context: I am using Git for an application I am developing. My application uses an open source library, that I patch for my own needs. This open source library is in SVN.

Problem: I am looking for a way to import and maintain this 3rd party component in my Git repository. I do not need to push my patches upstream.

The SVN repository for the open source library is quite standard.

trunk/
tags/
 - v1/
 - v2/
branches/

The directory structure in my Git working copy is very simple.

my_app/
lib/

How should I import the lib's source code from tag v1 in lib/?

And how can I merge or rebase new versions of the library when its dev team creates a tag v2 in their SVN repository?

To show a concrete example of the situation, I created a bash script:

# Create the open source library's SVN repo and its first tag.
svnadmin create lib_svn_repo/
svn checkout "file:///${PWD}/lib_svn_repo/" lib_working_copy
( cd lib_working_copy ; mkdir -p trunk tags branches ; svn add * ; svn commit -m 'Initialize SVN repo' ; cd trunk ; echo "print 'Hello v1'" >source.py ; svn add * ; svn commit -m 'Development for v1' ; cd .. ; svn up ; svn cp trunk/ tags/v1 ; svn commit -m 'Tag v1' ; sed --in-place 's/v1/v2/' trunk/* ; svn commit -m 'Development for v2' )

# Initialize my own project's git repository.
mkdir my_app
( cd $_ ; git init ; mkdir -p src lib ; touch src/.gitignore ; git add * ; git commit -m 'Initialize my app' )

# How to import the lib source code from tag v1 in the lib subdirectory???
# Expected: lib/ contains a source.py that displays "Hello v1".

# Commit local changes in my git repo.
( cd my_app/ ; echo "print 'My local modification'" >>lib/source.py ; git add * ; git commit -m 'Added local modification to the library' )

# Library dev team creates a tag v2.
( cd lib_working_copy ; svn up ; svn cp trunk/ tags/v2 ; svn commit -m 'Tag v2' )

# How to merge or rebase lib/ on tag v2???
# Expected: lib/ contains a source.py file that displays both "Hello v2" and "My local modification".

Upvotes: 2

Views: 161

Answers (1)

Michael
Michael

Reputation: 10474

Then (since you do not need history) I suggest you export the svn repo and import it into your git repository as just files, this is easiest.

Then monitor the changes of the tags in your external svn repo that you care about and apply diffs based on the external svn repo to your git repository as patches.

Upvotes: 1

Related Questions