Difference between revisions of "Git-svn"

From Planets
Jump to: navigation, search
(Contact for svn and git admin rights)
m (pre-push hook: typo)
 
Line 31: Line 31:
 
It has been modified to run two main commands: a '''git svn rebase''', followed by a '''git svn dcommit''' (see [[#git_svn_commands|below]]).
 
It has been modified to run two main commands: a '''git svn rebase''', followed by a '''git svn dcommit''' (see [[#git_svn_commands|below]]).
  
Due to how the pre-push hook is designed, you will need to run the the ''git push'' command twice.
+
Due to how the pre-push hook is designed, you will need to run the ''git push'' command twice.
 
The way the script works is summarized in the following diagram.
 
The way the script works is summarized in the following diagram.
 
[[File:pre-push.png|800px]]
 
[[File:pre-push.png|800px]]
Line 38: Line 38:
  
 
The pre-push hook is designed to push the commits as they were ''before'' entering the hook. And, since the ''git svn dcommit'' command changes the hashes of the commits during the hook, the commits that would be pushed after the hook would be the ones before the ''git svn dcommit'' and therefore the git remote master branch would be late compared to the svn repository. The script thus returns with an 'error', telling the user a second push is required. The second push will effectively push the new commits on the git remote master branch. Note that the svn is updated after the first push.
 
The pre-push hook is designed to push the commits as they were ''before'' entering the hook. And, since the ''git svn dcommit'' command changes the hashes of the commits during the hook, the commits that would be pushed after the hook would be the ones before the ''git svn dcommit'' and therefore the git remote master branch would be late compared to the svn repository. The script thus returns with an 'error', telling the user a second push is required. The second push will effectively push the new commits on the git remote master branch. Note that the svn is updated after the first push.
 
  
 
== git svn commands ==
 
== git svn commands ==

Latest revision as of 14:00, 15 October 2024

Git-svn is an extension of git that allows a git branch to commit to (and get updates from) a svn repository. This page explains how to install it and use it in the context of the PCM project.

Admin rights

Once you have gone through the installation process below, you will be required to have admin access to both the svn and the git. For this, please contact either Ehouarn Millour or Laurent Fairhead.

Installation

Git-svn can be installed via the following command on a linux system:

sudo apt install git-svn

To simplify things, a script has been created to make the link and ensure the svn is up-to-date/updated when you use git push.


The installation script can be found in the repository in the UTIL folder. You can run it with:

./UTIL/git_init.sh

The script will:

  • Initialize the git-svn branch to follow the svn repository,
  • Install the pre-push hook in your .git/hooks folder.

pre-push hook

This hook is launched each time you run the git push command. It has been modified to run two main commands: a git svn rebase, followed by a git svn dcommit (see below).

Due to how the pre-push hook is designed, you will need to run the git push command twice. The way the script works is summarized in the following diagram. Pre-push.png

The reason why two pushes are necessary is detailed below:

The pre-push hook is designed to push the commits as they were before entering the hook. And, since the git svn dcommit command changes the hashes of the commits during the hook, the commits that would be pushed after the hook would be the ones before the git svn dcommit and therefore the git remote master branch would be late compared to the svn repository. The script thus returns with an 'error', telling the user a second push is required. The second push will effectively push the new commits on the git remote master branch. Note that the svn is updated after the first push.

git svn commands

There are two main commands related to this system:

  • git svn rebase: This command will get changes from the svn and try to apply your local changes on top of it.
  • git svn dcommit: This command will change the hashes of local commits (adding the svn revision to the name of the commit) and commit to the svn. The local commits are not pushed to the git remote repository.