Difference between revisions of "Import from SVN"

From Gcube Wiki
Jump to: navigation, search
(Clone the SVN repository)
(Clone the SVN repository)
Line 94: Line 94:
 
</source>
 
</source>
  
= Clone the SVN repository =
+
 
 +
= SVN Repository Layouts=
 +
 
 +
== Standard Layout ==
 +
[[File:SNVStardardLayout.png|200px]]
 +
 
 +
== Non-Standard Layout ==
 +
[[File:SVNNonStandardLayout.png|200px]]
 +
 
 +
= Clone the SVN Repository =
 
The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of the SVN repo, the command needs to be configured differently.
 
The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of the SVN repo, the command needs to be configured differently.
  

Revision as of 14:59, 11 May 2019

This guide explains how to migrate a project from SVN to Git.

Download migration utilities

For an easy reference in this guide, the migration scripts is downloaded in the home folder:

 cd $HOME &&  wget https://bitbucket.org/atlassian/svn-migration-scripts/downloads/svn-migration-scripts.jar

Install git-svn

Ubuntu

On Ubuntu, if you you get this output:

$ java -jar ./svn-migration-scripts.jar verify  
svn-migration-scripts: using version 0.1.56bbc7f 
Git: using version 2.17.1  
Subversion: using version 1.9.7
git: 'svn' is not a git command. See 'git --help'.
The most similar commands are
fsck
mv
show
git-svn: ERROR: Unable to determine version.

You must install the git-svn package by running:

$ sudo apt install git-svn

Now, you will get something like this:

$ java -jar ./svn-migration-scripts.jar verify
svn-migration-scripts: using version 0.1.56bbc7f
Git: using version 2.17.1
Subversion: using version 1.9.7
git-svn: using version 2.17.1

Mount a case-sensitive disk image (for Mac OS)

Check if this step is needed by running:

java -jar ~/svn-migration-scripts.jar verify
 
svn-migration-scripts: using version 0.1.56bbc7f
Git: using version 2.11.0
Subversion: using version 1.9.4
git-svn: using version 2.11.0
You appear to be running on a case-insensitive file-system. This is unsupported, and can result in data loss.

Following the warning, we create a disk image dedicated to the migration activities:

java -jar ~/svn-migration-scripts.jar create-disk-image 5 GitMigration
 
created: /Users/manuelesimi/GitMigration.sparseimage
/dev/disk2     		 GUID_partition_scheme     		 
/dev/disk2s1   		 EFI                       		 
/dev/disk2s2   		 Apple_HFS                 		 /Users/manuelesimi/GitMigration
The disk image was created successfully and mounted as: /Users/manuelesimi/GitMigration

Extract the author(s) information

 cd ~/GitMigration
 java -jar ~/svn-migration-scripts.jar authors https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST  > authors.txt
About to create the authors file.


Alternative (pure SVN):

svn co https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST
cd gxREST
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

Edit the authors file

You need to edit the file and add the correct email address (i.e. the address configured in the Git service) for each listed author:

> cat authors.txt
luca.frosini = luca.frosini <luca.frosini@mycompany.com>
lucio.lelii = lucio.lelii <lucio.lelii@mycompany.com>
manuele.simi = manuele.simi <manuele.simi@mycompany.com
> vi authors.txt
 
> cat authors.txt
luca.frosini = luca.frosini <luca.frosini@isti.cnr.it>
lucio.lelii = lucio.lelii <lucio.lelii@isti.cnr.it>
manuele.simi = manuele.simi <manuele.simi@isti.cnr.it>


SVN Repository Layouts

Standard Layout

SNVStardardLayout.png

Non-Standard Layout

SVNNonStandardLayout.png

Clone the SVN Repository

The git svn clone command transforms the trunk, branches, and tags in your SVN repository into a new Git repository. Depending on the structure of the SVN repo, the command needs to be configured differently.

> git svn clone --authors-file=authors.txt --follow-parent  https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST \
  --username manuele.simi gxRest
 
Note: --follow-parent makes it slower, but it’s needed if the SVN folder has been moved around.
 
Initialized empty Git repository in /Users/manuelesimi/GitMigration/gxRest/.git/
 
This may take a while on large repositories
Checked through r173000
 
Checked Ahrough .classpath
 
    A    pom.xml
    A    gxJRS/.classpath
    A    gxJRS/.project
    A    gxJRS/distro/profile.xml
    A    gxJRS/distro/LICENSE
    A    gxJRS/distro/changelog.xml
    A    gxJRS/distro/README
    A    gxJRS/src/test/java/org/gcube/common/gxrest/request/GXWebTargetAdapterRequestTest.java
    A    gxJRS/src/test/java/org/gcube/common/gxrest/request/GXHTTPStringRequestTest.java
    A    gxJRS/src/test/resources/logback-test.xml
    A    gxJRS/src/main/java/org/gcube/common/gxrest/methods/package-info.java
    A    gxJRS/src/main/java/org/gcube/common/gxrest/request/GXHTTPStreamRequest.java
    A    gxJRS/src/main/java/org/gcube/common/gxrest/request/package-info.java
    A    gxJRS/src/main/java/org/gcube/common/gxrest/request/GXWebTargetAdapterRequest.java
 
    [omitted output]
 
    A    gxJRS/src/main/java/org/gcube/common/gxrest/response/entity/SerializableErrorEntityTextWriter.java
    A    gxJRS/src/main/java/org/gcube/common/gxrest/response/entity/SerializableErrorEntityTextReader.java
    M    gxJRS/src/main/java/org/gcube/common/gxrest/response/entity/SerializableErrorEntity.java
r178787 = ac04855b00de818f2095d0784eb68c51a6ec9f77 (refs/remotes/git-svn)
Checked out HEAD:
  https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST r178787
creating empty directory: gxHTTP/src/main/resources
creating empty directory: gxJRS/src/main/resources
creating empty directory: gxJRS/src/test/java/org/gcube/common/gxrest/response

Do note that the command above DO NOT import the SVN branches because the repo does not have the standard SVN layout (/trunk, /branches, and /tags directory layout).

If the SVN repository doesn’t have a standard layout and you want to import everything, you need to provide the locations of your trunk, branches, and tags using the --trunk, --branches, and --tags command line options

Rename “trunk” branch to “master” (if needed)

> git branch
* trunk
> git branch -m trunk master
> git branch
* master

Check the imported history

> git log -10
commit ac04855b00de818f2095d0784eb68c51a6ec9f77
Author: manuele.simi <manuele.simi@isti.cnr.it>
Date:   Sun Mar 31 03:39:06 2019 +0000
 
	Add JAX-RS MessageBodyWriter/Reader responsible for converting SerializableErrorEntity to/from a stream.
 
	git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST@178787 82a268e6-3cf1-43bd-a215-b396298e98cf
 
commit 6eb3f608dbe31c50578e46c53e16c469a0cc7f0c
Author: manuele.simi <manuele.simi@isti.cnr.it>
Date:   Sat Mar 30 19:58:21 2019 +0000
 
	Tweak some javadoc.
 
	git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/gxREST@178786 82a268e6-3cf1-43bd-a215-b396298e98cf

Add code-repo’s Git repository as new remote

Do note that, before running this step, you need to create a new Git repository.

> git remote add origin https://code-repo.d4science.org/manuele.simi/gxRest.git
> git remote -v
origin    https://code-repo.d4science.org/manuele.simi/gxRest.git (fetch)
origin    https://code-repo.d4science.org/manuele.simi/gxRest.git (push)

Push the local repository to the new remote

> git push --set-upstream --force origin master
Counting objects: 168, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (125/125), done.
Writing objects: 100% (168/168), 39.47 KiB | 0 bytes/s, done.
Total 168 (delta 44), reused 0 (delta 0)
remote: Resolving deltas: 100% (44/44), done.
To https://code-repo.d4science.org/manuele.simi/gxRest.git
 + 4ec6b48...ac04855 master -> master (forced update)
Branch master set up to track remote branch master from origin.

Clone the repository and create a working copy

> cd ~/Work/CNR/Projects/Git/
> git clone https://code-repo.d4science.org/manuele.simi/gxRest.git
Cloning into 'gxRest'...
remote: Counting objects: 168, done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 168 (delta 44), reused 168 (delta 44)
Receiving objects: 100% (168/168), 39.47 KiB | 0 bytes/s, done.
Resolving deltas: 100% (44/44), done.

Configure authors info

Single repo configuration

In the root folder of the repository:

> git config user.email "manuele.simi@isti.cnr.it"
> git config user.name "Manuele Simi"

Global configuration (all repos on this computer)

In any folder:

> git config --global user.email "manuele.simi@isti.cnr.it"
> git config --global user.name "Manuele Simi"

Back to the CI guide.