The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

git-stitch-repo - Stitch several git repositories into a git-fast-import stream

SYNOPSIS

git-stitch-repo repo1 repo2:dir2 ...

DESCRIPTION

git-stitch-repo will process the output of git-fast-export --all --date-order on the git repositories given on the command-line, and create a stream suitable for git-fast-import that will create a new repository containing all the commits in a new commit tree that respects the history of all the source repositories.

Typical usage is like this:

    $ ls
    A  B
    $ mkdir RESULT
    $ cd RESULT
    $ git-init
    $ git-stitch-repo ../A:A ../B:B | git-fast-import

The RESULT repository will contain all commits from repositories A and B, with the files from A in subdirectory A/ and the files from B in subdirectory B/.

git-stich-repo works perfectly with repositories that have a linear history (no merges). It has successfully been tested with 16 linear repositories, and produced the expected result.

Example

Imagine we have two repositories A and B that we want to stitch into a repository C so that all the files from A are in subdirectory A and all the files from B are in subdirectory B.

Note: in the following ASCII art graphs, horizontal order is chronological.

Repository A:

                topic
                '    ,master
          ,----A3---A5
         /         /
    A1--A2---A4---'

Branch master points to A5 and branch topic points to A3.

Repository B:

                           ,topic    ,master
           ,---------B3---B5---B7---B8
          /                   /
    B1---B2---B4---B6--------'

Branch master points to B8 and branch topic points to B5.

The RESULT repository should preserve chronology, commit relationships and branches as much as possible, while giving the impression that the directories A/ & B/ did live side-by-side all the time.

Assuming additional timestamps not shown on the above graphs, git-stitch-repo will produce a git-fast-import stream that will create the following history:

                                       ,topic-A
                      ,---------------A3---B3 master-A
                     /                      \ '    ,topic-B
                    /         ,--------------A5---B5
                   /         /                     \      ,master-B
   A1---B1---A2---B2---A4---B4---B6-----------------B7---B8

BUGS & IMPROVEMENTS

Any mathematician will tell you there are many many ways to stitch two trees together. This programs tries very hard not to create inconsistent history with regard to each input repository.

The current implementation can (and will be) improved. I'm very interested in test repositories that do not give the expected results.

One of the issues is that we currently refuse to stitch a node after a merge from another repository. For the current example, that would mean that any commit having A5 as a parent would be attached to B5, and not to B8.

Fixing this is in the TODO list.

AUTHOR

Philippe Bruhat (BooK), <book@cpan.org>.

ACKNOWLEDGEMENTS

The original version of this script was created as part of my work for BOOKING.COM, which authorized its publication/distribution under the same terms as Perl itself.

COPYRIGHT

Copyright 2008 Philippe Bruhat (BooK), All Rights Reserved.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.