Total Pageviews

Sunday, 29 January 2017

Git for Source Code Management !!!

For source code management, different organizations make use of different tools. In my previous post we discussed about one such SCM tool which is SVN. In this post, I am going to discuss about Git. Now a days Git is the most popular and commonly used SCM tool.

Unlike in SVN, Git makes use of two repos.

1. Local repo
                    This is local to developers workspace. His/her locally stored workspace.

2. Remote repo
                    This is actual repo maintained by Git server. Every time a developer works and commits to his local repo, if he/she is satisfied with the changes then he will push these changes to remote repo.

Why Organizations prefer Git than SVN:
            Main reason is, Git is a Distributed Version Controlling System and can be maintained both on premises and on cloud.

Distributed because: Every developer has their local repos distributed, but the main commits can be done/shared to/from the remote repo (Git server).

ON CLOUD:

               There are different online open source providers for hosting Git repo.

github, gitbasket and gitlab                         --- on cloud
stash, gitblit and gerrit                                  --- on premises
collaborator and gitblit                                  --- both

Open Github.com,



Click on Sign in and enter required details:



Choose according to wish, since for practice I am selecting public repository.


Fill in the details:


Click on New repository:


Give a name for your repo, If we include a README file, repo will be created along with it.


If you want a Private repo, then do.....



Find the Https URL:


Now all we need to do, is to install Gitblit client in our local machine. 

https://git-scm.com/download/win                         File: Git-2.11.0.3-64-bit.exe

It is a normal .exe, installation process is next--next--next...
Use command prompt or git bash (Git bash is preferable for Linux users)

       user@USER-PC MINGW64 ~$ pwd
              /c/Users/user
       user@USER-PC MINGW64 ~$ git --version
              git version 2.11.0.windows.3

Go to desired and use git clone to checkout our repo:

       user@USER-PC MINGW64 ~$ cd F:/
       user@USER-PC MINGW64 /f $ cd Workspace_local/
       user@USER-PC MINGW64 /f/Workspace_local $ ls
              antivir.txt  hp_sr.txt  subversion/
       user@USER-PC MINGW64 /f/Workspace_local $ git clone https://github.com/oncloudrepo/git_repo.git
              Cloning into 'git_repo'...
              remote: Counting objects: 3, done.
              remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3
              Unpacking objects: 100% (3/3), done.
       user@USER-PC MINGW64 /f/Workspace_local $ ls
              antivir.txt  git_repo/  hp_sr.txt  subversion/

       user@USER-PC MINGW64 /f/Workspace_local $ cd git_repo/
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ ls
              README.md
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $

Copied a file to my workspace..

       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ ls
              antivir.txt  README.md


       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git status
              On branch master
              Your branch is up-to-date with 'origin/master'.
              Untracked files:
                (use "git add <file>..." to include in what will be committed)
                     antivir.txt
              nothing added to commit but untracked files present (use "git add" to track)
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $

A file which is created, but yet to be added ==== UnTracked file

       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git add .
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git status
              On branch master
              Your branch is up-to-date with 'origin/master'.
              Changes to be committed:
                (use "git reset HEAD <file>..." to unstage)
                       new file:   antivir.txt
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $

Before committing, only README file is in repo....



A file which is added, but yet to be committed ===== Staged File

       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git commit -m "anti file add"
              [master 90ba8e9] anti file add
               Committer: USER <USER >
              Your name and email address were configured automatically based
              on your username and hostname. Please check that they are accurate.
              You can suppress this message by setting them explicitly. Run the
              following command and follow the instructions in your editor to edit
              your configuration file:
                         git config --global --edit
              After doing this, you may fix the identity used for this commit with:
                         git commit --amend --reset-author
                         1 file changed, 11 insertions(+)
                         create mode 100644 antivir.txt
              user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $

A file which is committed to local repo, but yet to be pushed ===== Tracked File

       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git status
              On branch master
              Your branch is ahead of 'origin/master' by 1 commit.
              (use "git push" to publish your local commits)
              nothing to commit, working tree clean
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $

So far file was committed to our local repo, now we need to push to remote repo to reflect these changes in Git server.

       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master) $ git push




              Counting objects: 3, done.
              Delta compression using up to 4 threads.
              Compressing objects: 100% (3/3), done.
              Writing objects: 100% (3/3), 399 bytes | 0 bytes/s, done.
              Total 3 (delta 0), reused 0 (delta 0)
              To https://github.com/oncloudrepo/git_repo.git
               1785bc4..90ba8e9  master -> master
       user@USER-PC MINGW64 /f/Workspace_local/git_repo (master)


My commits are pushed to my On cloud git repo successfully......

ON PREMISES:

To setup Git server within our Organization premises, we need a Windows/Unix server. Download and copy the files to the server. 

We access our Git server through browser, which means Gitblit is a Web application. To deploy a web application, we need Tomcat and to deploy war files we need JAVA.

So, I copied Tomcat and gitblit.war file to the server...

root@ubuntu-kvm:~# cd /home/ubu/
root@ubuntu-kvm:/home/ubu#
root@ubuntu-kvm:/home/ubu# ls
Desktop    Downloads  jenkins.war  Pictures  Templates
apache-tomcat-7.0.75.tar.gz  Documents  git.war    Music        Public    Videos
root@ubuntu-kvm:/home/ubu#

gunzip it....


root@ubuntu-kvm:/home/ubu# tar -zxf apache-tomcat-7.0.75.tar.gz 
root@ubuntu-kvm:/home/ubu# ls
apache-tomcat-7.0.75         Desktop    Downloads  jenkins.war  Pictures  Templates
apache-tomcat-7.0.75.tar.gz  Documents  git.war    Music        Public    Videos
root@ubuntu-kvm:/home/ubu#

root@ubuntu-kvm:/home/ubu# cd apache-tomcat-7.0.75/
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75# ls
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75#

root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75# cd webapps/
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps# cp ../../git.war . 
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps# ls
docs  examples  git.war  host-manager  manager  ROOT
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps#

root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps# cd ../bin/
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/bin# ls
bootstrap.jar       commons-daemon-native.tar.gz  digest.sh         startup.bat           tool-wrapper.sh
catalina.bat        configtest.bat                setclasspath.bat  startup.sh            version.bat
catalina.sh         configtest.sh                 setclasspath.sh   tomcat-juli.jar       version.sh
catalina-tasks.xml  daemon.sh                     shutdown.bat      tomcat-native.tar.gz
commons-daemon.jar  digest.bat                    shutdown.sh       tool-wrapper.bat
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/bin#

To start the Tomcat server....

root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/bin# ./startup.sh
Using CATALINA_BASE:   /home/ubu/apache-tomcat-7.0.75
Using CATALINA_HOME:   /home/ubu/apache-tomcat-7.0.75
Using CATALINA_TMPDIR: /home/ubu/apache-tomcat-7.0.75/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /home/ubu/apache-tomcat-7.0.75/bin/bootstrap.jar:/home/ubu/apache-tomcat-7.0.75/bin/tomcat-juli.jar
Tomcat started.
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/bin#




During the start of Tomcat server, war files will be deployed.... git folder was generated...



root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/bin# cd ../webapps

root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps# ls
docs  examples  git  git.war  host-manager  manager  ROOT
root@ubuntu-kvm:/home/ubu/apache-tomcat-7.0.75/webapps#

Enter URL along with "git" to access git.... Login username: admin and password: admin


Let us create new repo on premises through gitblit.... Choose name and type, then Create...



Use the URL which is generated for our repo to checkout the git repo.

user@USERS-PC MINGW64 /f/Workspace_local $ git clone ssh://admin@10.0.0.229:29418/git_onp_repo.git
                Cloning into 'git_onp_repo'...
                The authenticity of host '[10.0.0.229]:29418 ([10.0.0.229]:29418)' can't be established. RSA key fingerprint is SHA256:UqXvhPBG8s2CQAgJTc0IR5oqzAzJQv0mM7j+OgKcgng.0
                Are you sure you want to continue connecting (yes/no)? yes
                Warning: Permanently added '[10.0.0.229]:29418' (RSA) to the list of known hosts.
                Password authentication
                Password:
                remote: Counting objects: 3, done
                remote: Finding sources: 100% (3/3)
                remote: Getting sizes: 100% (2/2)
                remote: Compressing objects: 100% (72/72)
                remote: Total 3 (delta 0), reused 0 (delta 0)
                Receiving objects: 100% (3/3), done.
        user@USERS-PC MINGW64 /f/Workspace_local $

        user@USERS-PC MINGW64 /f/Workspace_local  $  ls
                antivir.txt  git_onp_repo/  git_repo/  hp_sr.txt  subversion/
        user@USERS-PC MINGW64 /f/Workspace_local $

        user@USERS-PC MINGW64 /f/Workspace_local $ cd git_onp_repo/
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ ls
                README.md
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

Create a new file ....

        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ tee -a first_file
                hi this is my first file thru git
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ ls
                first_file  README.md
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

Check the status and add it...

        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git status
                On branch master
                Your branch is up-to-date with 'origin/master'.
                Untracked files:
                (use "git add <file>..." to include in what will be committed)
                        first_file
                nothing added to commit but untracked files present (use "git add" to track)
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git add .
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git status
                On branch master
                Your branch is up-to-date with 'origin/master'.
                Changes to be committed:
                (use "git reset HEAD <file>..." to unstage)
                        new file:   first_file
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

Lets commit this..



        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git commit -m "1st file"
                [master e4c2887] 1st file
                Committer: USERS   <USERS  >
                Your name and email address were configured automatically based
                on your username and hostname. Please check that they are accurate.
                You can suppress this message by setting them explicitly. Run the
                following command and follow the instructions in your editor to edit
                your configuration file:
                           git config --global --edit
                After doing this, you may fix the identity used for this commit with:
                           git commit --amend --reset-author
                1 file changed, 0 insertions(+), 0 deletions(-)
                create mode 100644 first_file
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git status
                On branch master
                Your branch is ahead of 'origin/master' by 1 commit.
                (use "git push" to publish your local commits)
                nothing to commit, working tree clean
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $

To push these changes to remote repo...

        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $ git push
                        Password authentication
                        Password:
                        Counting objects: 3, done.
                        Delta compression using up to 4 threads.
                        Compressing objects: 100% (2/2), done.
                        Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done.
                        Total 3 (delta 0), reused 0 (delta 0)
                        remote: Updating references: 100% (1/1)
                        To ssh://10.0.0.229:29418/git_onp_repo.git
                              c5ef999..e4c2887  master -> master
        user@USERS-PC MINGW64 /f/Workspace_local/git_onp_repo (master) $






In this post we covered installing and deploying gitblit server. Committed few files to both local and remote repo, also both in on cloud and on premises git server...

################################################################################

Wednesday, 11 January 2017

SVN Commands and Administration !!!

In my previous post we discussed the concept of SVN and its installation. In this post I am going to show the working with commands of SVN from Client and administration part at the server end.

SVN is a source code management tool which is used by a developer to push the code to the actual SVN server. Sometimes different users may work on the same directory and files, so to avoid conflicts related to data, svn uses "commit" which allows whether a file can be committed or any other user is still working on it.

If other users working on it, svn throws us a message asking whether to continue with the changes by A developer or to commit another developer B's work.

Let us get into the action by practicing few basic commands:

We have seen already, how to add a file and commit. Now lets see how to add a directory which contains different files.

F:\Workspace_local>svn st
svn: warning: W155007: 'F:\Workspace_local' is not a working copy

F:\Workspace_local>

Important rule never forget to perform work/ execute svn cmds in your Workspace.

F:\Workspace_local>cd subversion
F:\Workspace_local\subversion>
F:\Workspace_local\subversion>svn st  --- just to know workspace is in sync with repo or not....
F:\Workspace_local\subversion>

Before adding a directory to my repo,

F:\Workspace_local\subversion>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local\subversion

01/09/2017  05:51 PM    <DIR>          .
01/09/2017  05:51 PM    <DIR>          ..
01/09/2017  05:50 PM             1,914 README.md
01/09/2017  05:53 PM                17 Welcome.txt
               2 File(s)          1,931 bytes
               2 Dir(s)  230,929,895,424 bytes free
F:\Workspace_local\subversion>
Adding a folder named "New folder", it contains some text files and a image file.

Now add it to our server repo, 

F:\Workspace_local\subversion>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local\subversion

01/11/2017  07:17 PM    <DIR>          .
01/11/2017  07:17 PM    <DIR>          ..
01/11/2017  07:13 PM    <DIR>          New folder
01/09/2017  05:50 PM             1,914 README.md
01/09/2017  05:53 PM                17 Welcome.txt
               2 File(s)          1,931 bytes
               3 Dir(s)  230,929,895,424 bytes free
F:\Workspace_local\subversion>        Above is, current status before commit and after copying..

F:\Workspace_local\subversion>svn st
?       New folder
F:\Workspace_local\subversion>        Status shows recent changes which are yet to sync local with repo..

It is time to add our directory...

F:\Workspace_local\subversion>svn add "New folder"
A         New folder
A  (bin)  New folder\Capture1.PNG
A         New folder\hp_sr.txt
A         New folder\antivir.txt
A         New folder\icici amts.txt
F:\Workspace_local\subversion>

Once added, we need to commit this to reflect in repo....


F:\Workspace_local\subversion>svn commit -m "adding newfolder to repo"
Adding         New folder
Adding  (bin)  New folder\Capture1.PNG
Adding         New folder\antivir.txt
Adding         New folder\hp_sr.txt
Adding         New folder\icici amts.txt
Transmitting file data ....
Committed revision 3.
F:\Workspace_local\subversion>



To delete a file from local and repo,

F:\Workspace_local\subversion>svn delete "New folder"\hp_sr.txt
D         New folder\hp_sr.txt
F:\Workspace_local\subversion>cd "New folder"
F:\Workspace_local\subversion\New folder>
F:\Workspace_local\subversion\New folder>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local\subversion\New folder

01/11/2017  07:22 PM    <DIR>          .
01/11/2017  07:22 PM    <DIR>          ..
02/15/2016  01:13 PM               157 antivir.txt
01/11/2017  07:12 PM           170,057 Capture1.PNG
09/08/2016  10:37 AM                50 icici amts.txt
               3 File(s)        170,264 bytes
               2 Dir(s)  230,929,723,392 bytes free
F:\Workspace_local\subversion\New folder>

So far this is temporary. If we check in browser, this won't be reflected at server end.

Before committing and after deleting at local, still we can view the file and its contents...

F:\Workspace_local\subversion\New folder>svn commit -m "deleted hp_sr"
Deleting       hp_sr.txt
Committed revision 4.
F:\Workspace_local\subversion\New folder>


After commit, it will be permanently deleted....

To check the logs, we have "svn log"command.

F:\Workspace_local\subversion>svn log -r3
------------------------------------------------------------------------
r3 | (no author) | 2017-01-11 19:18:45 -0500 (Wed, 11 Jan 2017) | 1 line

adding newfolder to repo
------------------------------------------------------------------------
F:\Workspace_local\subversion>

Similarly to view log for a range of revisions,

F:\Workspace_local\subversion>svn log -r3:4
------------------------------------------------------------------------
r3 | (no author) | 2017-01-11 19:18:45 -0500 (Wed, 11 Jan 2017) | 1 line

adding newfolder to repo
------------------------------------------------------------------------
r4 | (no author) | 2017-01-11 19:23:55 -0500 (Wed, 11 Jan 2017) | 1 line

deleted hp_sr
------------------------------------------------------------------------
F:\Workspace_local\subversion>

Whenever we feel like updating repo with older we have "update" command,
If we consider that our previous deletion is not a proper step and want changes to go back.

F:\Workspace_local\subversion\New folder>svn update -r3
Updating '.':
A    hp_sr.txt
Updated to revision 3.
F:\Workspace_local\subversion\New folder>

F:\Workspace_local\subversion\New folder>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local\subversion\New folder

01/11/2017  07:32 PM    <DIR>          .
01/11/2017  07:32 PM    <DIR>          ..
02/15/2016  01:13 PM               157 antivir.txt
01/11/2017  07:12 PM           170,057 Capture1.PNG
01/11/2017  07:32 PM                11 hp_sr.txt
09/08/2016  10:37 AM                50 icici amts.txt
               4 File(s)        170,275 bytes
               2 Dir(s)  230,929,723,392 bytes free
F:\Workspace_local\subversion\New folder>

There are two other main commands with special usage. When it comes to a developer, he has his workspace checked out with the repo. But what if a one time user want to push some data from his PC. Similarly what if someone wants to pull a single file.

Usually we can use checkout command to push entire directory, so to push a single file we have "svn import" command.

Note: To make use of "import" command, no need to run it from Workspace. I copied a file outside of my workspace "subversion".

F:\Workspace_local>svn st
svn: warning: W155007: 'F:\Workspace_local' is not a working copy
F:\Workspace_local>

F:\Workspace_local>svn import hp_sr.txt http://10.0.0.218:81/subversion/New\folder/hp_sr.txt -m "adding hp_sr thru import"
Adding         hp_sr.txt
Committed revision 5.
F:\Workspace_local>

One import to New\folder... and below import to "subversion" (Workspace)...

F:\Workspace_local>svn import hp_sr.txt http://10.0.0.218:81/subversion/hp_sr.txt -m "adding hp_sr thru import"
Adding         hp_sr.txt
Committed revision 6.
F:\Workspace_local>
F:\Workspace_local>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local

01/11/2017  07:39 PM    <DIR>          .
01/11/2017  07:39 PM    <DIR>          ..
01/11/2017  07:32 PM                11 hp_sr.txt
01/11/2017  07:17 PM    <DIR>          subversion
               1 File(s)             11 bytes
               3 Dir(s)  230,929,723,392 bytes free

F:\Workspace_local>
To fetch/pull a single file, we make use of "export" command... We can run it from outside of workspace. 

F:\Workspace_local>svn export http://10.0.0.218:81/subversion/New%20folder/antivir.txt
A    antivir.txt
Export complete.

F:\Workspace_local>
F:\Workspace_local>dir
 Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA

 Directory of F:\Workspace_local

01/11/2017  07:48 PM    <DIR>          .
01/11/2017  07:48 PM    <DIR>          ..
01/11/2017  07:18 PM               157 antivir.txt
01/11/2017  07:32 PM                11 hp_sr.txt
01/11/2017  07:17 PM    <DIR>          subversion
               2 File(s)            168 bytes
               3 Dir(s)  230,929,723,392 bytes free

F:\Workspace_local>




Other than these, there are few other commands like "svn revert" to revert any operations before committing, and "svn diff" used to view difference between two files.

So far we completed svn commands practical from client side. Now let us see some SVN admin tasks. 

Admin should perform tasks related to Authorization, backups of repo and restricting few tasks or applying conditions to perform a task.

Observe the output:

F:\Workspace_local\subversion>svn log -r2:6
------------------------------------------------------------------------
r2 | (no author) | 2017-01-09 18:01:13 -0500 (Mon, 09 Jan 2017) | 1 line

1st Commit
------------------------------------------------------------------------
r3 | (no author) | 2017-01-11 19:18:45 -0500 (Wed, 11 Jan 2017) | 1 line

adding newfolder to repo
------------------------------------------------------------------------
r4 | (no author) | 2017-01-11 19:23:55 -0500 (Wed, 11 Jan 2017) | 1 line

deleted hp_sr
------------------------------------------------------------------------
r5 | (no author) | 2017-01-11 19:44:45 -0500 (Wed, 11 Jan 2017) | 1 line

adding hp_sr thru import
------------------------------------------------------------------------
r6 | (no author) | 2017-01-11 19:46:34 -0500 (Wed, 11 Jan 2017) | 1 line

adding hp_sr thru import
------------------------------------------------------------------------


F:\Workspace_local\subversion>

We are working with anonymous user, we can restrict this by creating separate users and also by restricting their access to certain level (directories).

To create users,

root@ubuntu-new:/opt/subversion-1.9.5-0# cd apache2/
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# htpasswd -c /opt/subversion-1.9.5-0/svn_users dev1
New password:
Re-type new password:
Adding password for user dev1
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

For second developer,  used -m to modify the users file. If we use -c it will create the file again...

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# htpasswd -m /opt/subversion-1.9.5-0/svn_users dev2
New password:
Re-type new password:
Adding password for user dev2
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# cat /opt/subversion-1.9.5-0/svn_users
dev1:$apr1$hb7S2CtJ$GwVa5dEBDzY3EFS/K6yj71
dev2:$apr1$vhccSww7$y.W95.QX5ofsBosFPcxZH0
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

Let me show, if I use -c option:

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# htpasswd -c /opt/subversion-1.9.5-0/svn_users dev3
New password:
Re-type new password:
Adding password for user dev3
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# cat /opt/subversion-1.9.5-0/svn_users
dev3:$apr1$Fa3y4u5Q$INzi63RXzYiThQZ9hm8S.1
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

Create a new file with name "svn_access" (can give according to admin wish)

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2# vi /opt/subversion-1.9.5-0/svn_access
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2#

root@ubuntu-new:/opt/subversion-1.9.5-0# cat svn_access
[subversion:/]                        ------ can mention desired directory
dev3=rw
[groups]                        ------ can assign a group to a user

root@ubuntu-new:/opt/subversion-1.9.5-0#

To enable this authentication in our apache server,

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2/conf# vi httpd.conf
root@ubuntu-new:/opt/subversion-1.9.5-0/apache2/conf#

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2/conf# cat httpd.conf | tail -12
Include "/opt/subversion-1.9.5-0/apache2/conf/ssi.conf"
Include "/opt/subversion-1.9.5-0/apache2/conf/bitnami/bitnami.conf"
<Location /subversion>
DAV svn
SVNPath "/opt/subversion-1.9.5-0/repository"

AuthType Basic
AuthName "Subversion Project1"
AuthUserFile /opt/subversion-1.9.5-0/svn_users
Require valid-user
AuthzSVNAccessFile /opt/subversion-1.9.5-0/svn_access
</Location>

root@ubuntu-new:/opt/subversion-1.9.5-0/apache2/conf#

Then restart the apache server,

root@ubuntu-new:/opt/subversion-1.9.5-0# ./ctlscript.sh restart
/opt/subversion-1.9.5-0/subversion/scripts/ctl.sh : subversion stopped
Syntax OK
/opt/subversion-1.9.5-0/apache2/scripts/ctl.sh : httpd stopped
Syntax OK
/opt/subversion-1.9.5-0/apache2/scripts/ctl.sh : httpd started at port 81
/opt/subversion-1.9.5-0/subversion/scripts/ctl.sh : subversion started at port 3690

root@ubuntu-new:/opt/subversion-1.9.5-0#

Now try to open in browser, this time server will pop-up the Authentication window....
Use of svn_access file, is to restrict the access permissions of a user...

root@ubuntu-new:/opt/subversion-1.9.5-0# vi svn_access
root@ubuntu-new:/opt/subversion-1.9.5-0#
root@ubuntu-new:/opt/subversion-1.9.5-0#
root@ubuntu-new:/opt/subversion-1.9.5-0# cat svn_access
[subversion:/New folder]
dev3=rw
[groups]
root@ubuntu-new:/opt/subversion-1.9.5-0#

Provided access only to "New folder" for dev3 user...

Before changing access,
After providing new access, he can only view and edit "New folder"
Another admin task is to handle backup and restore of repo.

To take dump,

svnadmin dump /opt/subversion-1.9.5-0/repository/ > /file_loc

To load it,

svnadmin load /opt/subversion-1.9.5-0/repository/ < /file_loc

Similar to these, an admin can restrict commits with some conditions. Admin can restrict few types of files to get added to server.

root@ubuntu-new:/opt/subversion-1.9.5-0/repository# cd hooks
root@ubuntu-new:/opt/subversion-1.9.5-0/repository/hooks#

In this hooks directory, we have different templates where we can write our scripts to restrict any kind of task...

root@ubuntu-new:/opt/subversion-1.9.5-0/repository/hooks# ls
post-commit.tmpl  post-revprop-change.tmpl  pre-commit.tmpl  pre-revprop-change.tmpl  start-commit.tmpl
post-lock.tmpl    post-unlock.tmpl          pre-lock.tmpl    pre-unlock.tmpl

root@ubuntu-new:/opt/subversion-1.9.5-0/repository/hooks#

For example, we can write a script inside "pre-commit.tmpl" which needs to be executed before commiting any type of file/dir...

An admin can perform/restrict different tasks, in this post I covered few of them....

################################################################################

Monday, 9 January 2017

SubVersion (SVN) for Source Code Management !!!

In any Software project, there are different methodologies and tools used during the project. Coming to methodologies there are Agile and Waterfall. Similarly when it comes to tools there are many tools we use during different stages of project.

In this post I am going to discuss about such a tool which widely used for Source Code Management during a Software Project. In Production environment, for any project there will be different releases. 

All these releases will be scheduled with some timelines. To avoid confusion related to source code, we need some tools to manage it. SubVersion (SVN) is tool many of the Software Companies make use for Code management.

Using SVN, we create a directory structure which helps to maintain clarity about the code related to every release. This proper structure make use of following branching strategies:

1. Sequential 

                Sequential is a strategy, in which we can work on one release after completion of the other. No work related to different releases can be carried out during single timeline.

R2 will be started after completion of R1. Similarly R3 will be started after R2. So there will be no confusion in moving the developers data to production. But in real time this strategy will not be a good one.

2. Parallel

                 Most of the Clients cannot wait to start working on R2 till the R1 completes. So then comes the Parallel branching strategy. In Parallel, we can work on more than one Release at single point of time. 

This helps to overcome the problem of longer duration for every release as we face in Sequential branching. To maintain proper directory structure, after completion of coding for each release we update the production with delta changes.

There is a problem with this strategy. For initial releases the updation of production is something like we merge 90% of new data to 10% of old data. But when it comes to 15th release or more, to update 10% of new data we need to update it by merging with 90% of old data.

3. Merging

                  To avoid the problem with Parallel branching, the Merging strategy was evolved. I will make use of two locations Core and Prod. Prod is the data what actually our Production server contains and core is data at developer end.

After completion of every release the Core should equals with Prod. When we use this strategy, during the development of R15 data which we need to update to Prod is just R13, R14 and R15 (Since R13,R14 may be in development stage).

What I mean, when R1 is released, core=prod=R1+old
                               R2 is released, core=R1+old  Prod=R2+R1+old to make Core=Prod
                                           we copy R2 to core......
                                        .
                                        .
                                        .
                                        .
                                        .
                               R8 , core=R1...R6/7+old and Prod=R8 + R1....R6/7 + old
                                            So to make Core=Prod, copy back R8 to Core.
                                        .
                                        .
                                        .
                                        .
                                        .
                    For R15, we need delta changes from R13, R14 and R15 only....
But in Parallel branching, we need to update Prod with R15,R14,R13 changes by merging with R1....R12 data.

Now lets see some practical part like installing SVN and by working with some commands usually used by developers at Client level....

I am using svn from bitnami which is parented by APACHE.


root@ubuntu-new:~# cd /home/ubu/
root@ubuntu-new:/home/ubu#
root@ubuntu-new:/home/ubu# ls
bitnami-subversion-1.9.5-0-linux-x64-installer.run  Music
Desktop                                             Pictures
docker-master.zip                                   Public
Documents                                           Setup-Subversion-1.8.17.msi
Downloads                                           Templates
libapache2-mod-php5_5.3.10-1ubuntu3.25_amd64.deb    Videos
root@ubuntu-new:/home/ubu#

Already downloaded and copied my installer file to my Ubuntu server...

root@ubuntu-new:/home/ubu# ./bitnami-subversion-1.9.5-0-linux-x64-installer.run
----------------------------------------------------------------------------
Welcome to the Bitnami Subversion Stack Setup Wizard.

----------------------------------------------------------------------------
Installation folder

Please, choose a folder to install Bitnami Subversion Stack

Select a folder [/opt/subversion-1.9.5-0]:

----------------------------------------------------------------------------
Web Server Port

Choose a port that is not currently in use, such as port 81.

Apache Web Server Port [81]:

----------------------------------------------------------------------------
Repository

Please configure your repository

Path to repository [/opt/subversion-1.9.5-0/repository]:

----------------------------------------------------------------------------
Setup is now ready to begin installing Bitnami Subversion Stack on your
computer.

Do you want to continue? [Y/n]: Y

----------------------------------------------------------------------------
Please wait while Setup installs Bitnami Subversion Stack on your computer.

 Installing
 0% ______________ 50% ______________ 100%
 #########################################

----------------------------------------------------------------------------
Setup has finished installing Bitnami Subversion Stack on your computer.

Launch Bitnami Subversion Stack [Y/n]: Y

root@ubuntu-new:/home/ubu#

To Check the status of our subversion...


root@ubuntu-new:/home/ubu# cd 

/opt/subversion-1.9.5-0
root@ubuntu-new:/opt/subversion-1.9.5-0# ls
apache2        config        licenses               README.txt  sqlite      uninstall.dat
changelog.txt  ctlscript.sh  manager-linux-x64.run  repository  subversion  use_subversion
common         img           properties.ini         scripts     uninstall
root@ubuntu-new:/opt/subversion-1.9.5-0#

root@ubuntu-new:/opt/subversion-1.9.5-0# ./ctlscript.sh status
subversion already running
apache already running
root@ubuntu-new:/opt/subversion-1.9.5-0#

Through browser we can check.....


Now to work with SVN CLI, lets install the client in our Windows.
We need to checkout the SVN server using the URL in our desired location from our client...


Most important thing is, Workspace is the place where a developer can do all the coding. We can add and then commit the files which are inside our Workspace.

As you see, soon after checkout command, there is a subversion directory within which readme file was created. Our workspace is the subversion directory...


Above I tried executing svn commands outside the workspace, it didn't allow me. But when I tried changing directory to subversion then I am able to execute "svn info".

Let us try creating a file and adding it to our SVN server.


Above I created Welcome file with some text in it.... 
Soon after creating a file, we can check the "svn status" command....

Command Prompt output of our SVN Client machine....

F:\Workspace_local\subversion>
F:\Workspace_local\subversion>svn status
?       Welcome.txt

F:\Workspace_local\subversion>

In the above output, ? represents this file is not yet reflected on our server....
First add it, then we need to commit....

Note: Commit always needs a message, we can give any message so that whenever we check the logs, we can remember what are the changes done with this commit....

F:\Workspace_local\subversion>svn add Welcome.txt
A         Welcome.txt

F:\Workspace_local\subversion>svn commit Welcome.txt -m "1st Commit"
Adding         Welcome.txt
Transmitting file data .
Committed revision 2.

F:\Workspace_local\subversion>

This time if we check status command, no new changes done at client side. All data is in sync with server...

F:\Workspace_local\subversion>svn status
F:\Workspace_local\subversion>

Screenshots from browser,

Revision number before commit of new file....

Revision number incremented after commit of new file....

We can view the content of the file....

################################################################################