Tuesday 26 December 2017

TechTip - SVN to GIT Migration - Renaming/Refactoring Projects

During SVN to GIT Migration, I have faced one challenge that is renaming/restructuring projects while migration.

Let say, you have following maven project in SVN

old-project
-- src
-- pom.xml

Now you want this project to be renamed while migrating to GIT and it should look like below:

new-project
-- src
-- pom.xml

If you try changing this name while cloning projects from SVN to GIT just like below. You will loose history after migration. But you must think about solution where history remain as it is but your project can be renamed or restructured.

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt  svn://xyz.com/SRC/Trunk/old-project new-project

How to do it? 

Actually, there is no rocket science I have applied here. Its pretty simple. You just need to refactor/rename your projects in SVN itself. The good part is, SVN still maintains full history even after renaming the folder names while copying from one place to another. This is really one of the great features in SVN that I will miss in GIT for sure.

First copy your project in SVN itself with required name using below command

svn copy <source-svn-url>   <destination-svn-url> -m "Renamed project name"


Example:

svn copy svn://xyz.com/SRC/Trunk/old-project  svn://xyz.com/SRC/GIT-SRC/new-project -m "Renamed project name from old-project to new-project"

Do whatever refactoring you want to do with your project in SVN itself. Now once you are ready with structure of your  project which must be there in GIT as repository, you can use your refactored location to clone project.

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt  svn://xyz.com/SRC/GIT-SRC/new-project new-project

After migration in GIT, you can see full change history of old-project including message 'Renamed project name from old-project to new-project' that you just did while renaming the project in SVN itself from old to new location.

Renaming/Refactoring was a big challenge but with this simple approach I could successfully renamed/refactored projects while SVN to GIT migration.

If you are looking for post about how to migrate from SVN to GIT. You can refer my another post.


TechTip - How to embed html report within the Jenkins email notifications?

If you would like to send html report through Jenkins email notifications and looking for how to embed html report within the Jenkins email notifications, you can follow below steps:

Prerequisite

Ensure that your Jenkins has email-ext-plugin installed. If not, refer this and install it first.

Steps

Follow below steps to embed html file in email content:
  1. Go to your jenkins job and click on Configure.
  2. Go to Post Build Actions and then select Editable Email Notifications
  3. Select Content Type as HTML(text/plain)
  4. In the default content section replace $DEFAULT_CONTENT with following
           ${FILE,path=”relative path to html file”}

Example

For example, below is the absolute path for your html file. So you just need to pick bold marked as relative path and mention in path.

/app/jenkins/jobs/myjob/workspace/my-maven-module/target/site/surefire-report.html


${FILE,path="my-maven-module/target/site/surefire-report.html”}


This will place the surefire-report.html content in your email body.


Hope this tip is helpful for you.




Monday 18 December 2017

SVN to GIT Migration

In this post, I will be describing about how to migrate projects from SVN to GIT. You can follow below steps to migrate your projects into GIT from SVN.

Prerequisites 
You need following softwars to be available on your local machine before proceeding further:
  • Java runtime, version 6 or newer
  • Git, with git-svn included, version 1.7.7.5 or newer
  • Subversion, version 1.6.17 or newer.
Instructions 
Step-1: First download svn-migration-scripts.jar from Atlassian’s bitbucket account.

Step-2: You need to verify required software on your local machine. Execute below command to do the same:

java -jar svn-migration-scripts.jar verify

If you are moving your projects from SVN to GIT, you must want to maintain SVN history in GIT too. But it must be possible where committer names in SVN and GIT are different. For this you need to map committer's names with GIT committer email.

Step-3: Extract SVN committer’s names and store in text file. Execute below command to do same: 
java -jar svn-migration-scripts.jar authors <SVN-URL> > svn-committer.txt 
Step-4: Map every SVN committer’s information with their respective mail id's on GIT. 
For example, while extracting we got below file:

NarendraV = NarendraV < NarendraV@mycompany.com>
AbcX = AbcX <AbcX@mycompany.com>


Now change this file like below. Here, we need to ensure that given email id is configured in GIT. 

NarendraV = NarendraV <NarendraV@abc.com>
AbcX = AbcX AbcX@abc.com

Step-5: Execute below command for converting SVN project to GIT in local:

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt <svn-repository-url> <git-repository-name>

Ensure to replace <svn-repository-url> with your SVN repository URL and <git-repository-name> with repository name in GIT.

Step-4: Now create remote repository using BitBucket and push your local SVN to GIT converted project (done in step#5). 

First add remote repository to your local:

git remote add <GIT-Repository>

Now push project to remote repository using below command:

git push <remote-name> <remote-branch>

Example: git push origin develop

If you would like to get more detail, you can refer this link.

Challenges Faced
Here I would like to list out some challenges that we faced during SVN to GIT migration.
  • SVN branch did not follow the branch/trunk/tag standard structure
  • Restructuring/Refactoring projects in GIT. Please refer this link to get detail. 
  • Empty sub-folder migration from SVN to GIT
Hope this post helps you in SVN to GIT migration.

TechTip - Oracle SQL query to replace strings in clob column

If you are looking for oracle query to find and replace a string in clob column in bulk. You can find same tip below:

Create table having clob column.

create table MyClobTable ( column1 int, clob_column clob );


Create procedure to perform insertion in table

create or replace procedure MyProc( proc_column1 in int, proc_text in varchar2 )
as
begin
insert into MyClobTable values ( proc_column1, proc_text );
end;


Insert below two records in table.

exec MyProc(1, 'I am Narendra Verma and currently living in Atlanta. I visited a lot of places in Atlanta. Atlanta is a nice city in US.' );

exec MyProc(2, It is a great time to be in the City of Atlanta' );

commit;

Check if rows are inserted.

select * from MyClobTable;


Output:
1
I am Narendra Verma and currently living in Atlanta. I visited a lot of places in Atlanta. Atlanta is a nice city in US.

2
It is a great time to be in the City of Atlanta

Execute below to replace ‘Atlanta’ with 'Alpharetta' in all rows.

MERGE INTO MyClobTable A
     USING (SELECT column1,
                   TO_CLOB (REPLACE (clob_column, 'Atlanta', 'Alpharetta'))
                      AS updated_string
              FROM MyClobTable
             WHERE clob_column LIKE '%Atlanta%'
            )  B
        ON (A.column1 = B.column1)
WHEN MATCHED
THEN
   UPDATE SET A.clob_column = B.updated_string;


Check if 'Atlanta' word is replaced with 'Alpharetta' in all rows.

select * from MyClobTable;


Output:
1
I am Narendra Verma and currently living in Alpharetta. I visited a lot of places in Alpharetta. Alpharetta is a nice city in US.
2
It is a great time to be in the City of Alpharetta

Hope this tech tip helped you.