Difference between revisions of "Git svn"

From relax wiki
Jump to navigation Jump to search
m (added Category:Relax using HotCat)
 
(44 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{historical svn}}
 +
__TOC__
 +
 
= relax branches at github =
 
= relax branches at github =
 +
You should install [[msysgit]] on windows, to do the commands.
 +
 
== The relax_trunk ==
 
== The relax_trunk ==
 
Go to https://github.com/nmr-relax/relax_trunk <br>
 
Go to https://github.com/nmr-relax/relax_trunk <br>
Line 5: Line 10:
  
 
Now add this as a private remote, by setting the remote name '''hub'''.
 
Now add this as a private remote, by setting the remote name '''hub'''.
  md relax_trunk
+
<source lang="bash">
  cd relax_trunk
+
# Windows
 +
set relax_trunk="C:\WinPython27\relax\relax_trunk"
 +
set GIT_USER_NAME="GIT_USER_NAME"
 +
  md %relax_trunk%
 +
  cd %relax_trunk%
 +
# Linux
 +
bash ;
 +
relax_trunk=$HOME/relax/relax_trunk
 +
GIT_USER_NAME="GIT_USER_NAME"
 +
mkdir -p ${relax_trunk}
 +
cd $relax_trunk
 +
 
 
  git init  
 
  git init  
  git remote add origin https://GIT_USER_NAME@github.com/nmr-relax/relax_trunk.git
+
# Windows
  git remote add hub https://GIT_USER_NAME@github.com/GIT_USER_NAME/relax_trunk.git
+
git remote add origin https://%GIT_USER_NAME%@github.com/nmr-relax/relax_trunk.git
 +
git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_trunk.git
 +
# Linux
 +
  git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_trunk.git
 +
  git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_trunk.git
 +
 
 +
# Or if you have setup a SSH key in github, and tested with: ssh -T git@github.com
 +
git remote set-url origin git@github.com:nmr-relax/relax_trunk.git
 +
git remote set-url hub git@github.com:${GIT_USER_NAME}/relax_trunk.git
 +
 
 
  git fetch origin
 
  git fetch origin
 
  git checkout --track origin/master
 
  git checkout --track origin/master
 
  git fetch hub
 
  git fetch hub
Now we add the user scripts repo
+
 
  git clone https://GIT_USER_NAME@github.com/nmr-relax/relax_scripts.git
+
#Build
 +
scons
 +
 
 +
## Now we add the user scripts repo
 +
# Windows
 +
  git clone https://%GIT_USER_NAME%@github.com/nmr-relax/relax_scripts.git
 +
# Linux
 +
git clone https://${GIT_USER_NAME}@github.com/nmr-relax/relax_scripts.git
 +
</source>
 +
 
 
Go to https://github.com/nmr-relax/relax_scripts <br>
 
Go to https://github.com/nmr-relax/relax_scripts <br>
 
Click '''Fork'''.
 
Click '''Fork'''.
 +
<source lang="bash">
 
  cd relax_scripts
 
  cd relax_scripts
  git remote add hub https://GIT_USER_NAME@github.com/GIT_USER_NAME/relax_scripts.git
+
# Windows
 +
  git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_scripts.git
 +
# Linux
 +
git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_scripts.git
 +
</source>
  
 
== The relax_disp ==
 
== The relax_disp ==
Line 25: Line 64:
  
 
Now add this as a private remote, by setting the remote name '''hub'''.
 
Now add this as a private remote, by setting the remote name '''hub'''.
  md relax_disp
+
<source lang="bash">
  cd relax_disp
+
# Windows
 +
set relax_disp="C:\WinPython27\relax\relax_disp"
 +
set GIT_USER_NAME="GIT_USER_NAME"
 +
  md %relax_disp%
 +
  cd %relax_disp%
 +
# Linux
 +
bash ;
 +
relax_disp=$HOME/relax/relax_disp
 +
GIT_USER_NAME="GIT_USER_NAME"
 +
mkdir -p ${relax_disp}
 +
cd $relax_disp
 +
 
 
  git init  
 
  git init  
  git remote add origin https://GIT_USER_NAME@github.com/nmr-relax/relax_disp.git
+
# Windows
  git remote add hub https://GIT_USER_NAME@github.com/GIT_USER_NAME/relax_disp.git
+
  git remote add origin https://%GIT_USER_NAME%@github.com/nmr-relax/relax_disp.git
 +
  git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_disp.git
 +
# Linux
 +
git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_disp.git
 +
git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_disp.git
 +
 
 
  git fetch origin
 
  git fetch origin
 
  git checkout --track origin/master
 
  git checkout --track origin/master
 
  git fetch hub
 
  git fetch hub
Now we add the user scripts repo
+
 
  git submodule add https://GIT_USER_NAME@github.com/nmr-relax/relax_scripts.git
+
#Build
 +
scons
 +
 
 +
## Now we add the user scripts repo
 +
# Windows
 +
  git clone https://%GIT_USER_NAME%@github.com/nmr-relax/relax_scripts.git
 +
# Linux
 +
git clone https://${GIT_USER_NAME}@github.com/nmr-relax/relax_scripts.git
 +
</source>
 +
 
 
Go to https://github.com/nmr-relax/relax_scripts <br>
 
Go to https://github.com/nmr-relax/relax_scripts <br>
 
Click '''Fork'''.
 
Click '''Fork'''.
 +
<source lang="bash">
 
  cd relax_scripts
 
  cd relax_scripts
  git remote add hub https://GIT_USER_NAME@github.com/GIT_USER_NAME/relax_scripts.git
+
# Windows
 
+
  git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_scripts.git
= Get future updates =
+
# Linux
For future updates to the SVN revision HEAD, you now need to do a git svn rebase, which is very similar to: svn up
+
git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_scripts.git
git svn rebase
+
</source>
Check branch information
 
git branch -a
 
  
 
= How the import to github was done =
 
= How the import to github was done =
 
[http://www.tfnico.com/presentations/git-and-subversion Based on these posts] and on [http://trac.parrot.org/parrot/wiki/git-svn-tutorial this recommended post], and [http://john.albin.net/git/convert-subversion-to-git also this post.]
 
[http://www.tfnico.com/presentations/git-and-subversion Based on these posts] and on [http://trac.parrot.org/parrot/wiki/git-svn-tutorial this recommended post], and [http://john.albin.net/git/convert-subversion-to-git also this post.]
  
You should install [[msysgit]] on windows, to do the commands.
+
You need an [[Authors#authors.txt | authors.txt]] file, to correctly convert the metadata.
md C:\WinPython27\relax
+
<source lang="bash">
cd C:\WinPython27\relax
+
  bash ;
 
+
relax=$HOME/backup/relax ;
You need an [[Authors#authors.txt | authors.txt]] file, to correctly convert the metadata.  
+
relax_trunk=${relax}/relax_trunk ;
  git svn clone http://svn.gna.org/svn/relax/trunk --no-metadata -A authors.txt
+
relax_disp=${relax}/relax_disp ;
  copy authors.txt trunk
+
GIT_USER_NAME="GIT_USER_NAME"
 +
  mkdir -p ${relax_trunk} ${relax_disp} ;
  
  git svn clone http://svn.gna.org/svn/relax/branches/relax_disp --no-metadata -A authors.txt
+
  git svn clone http://svn.gna.org/svn/relax/trunk --no-metadata -A authors.txt ${relax_trunk} ;
  copy authors.txt relax_disp
+
  cp authors.txt ${relax_trunk} ;
 +
cat ${relax_trunk}/.git/config
 +
cp ${relax_trunk}/.git/config ${relax_trunk}/.git/config_bck
 +
awk '{gsub(a,b);print}' a=".*authorsfile =.*" b="        authorsfile = ${relax_trunk}/authors.txt" ${relax_trunk}/.git/config_bck > ${relax_trunk}/.git/config
 +
cat ${relax_trunk}/.git/config
  
  #Build
+
  git svn clone http://svn.gna.org/svn/relax/branches/relax_disp --no-metadata -A authors.txt ${relax_disp} ;
  cd trunk
+
  cp authors.txt ${relax_disp} ;
  scons
+
  cat ${relax_disp}/.git/config
  cd ..
+
  cp ${relax_disp}/.git/config ${relax_disp}/.git/config_bck
  cd relax_disp
+
  awk '{gsub(a,b);print}' a=".*authorsfile =.*" b="        authorsfile = ${relax_disp}/authors.txt" ${relax_disp}/.git/config_bck > ${relax_disp}/.git/config
  scons
+
  cat ${relax_disp}/.git/config
 +
</source>
  
 
== Setup remotes to github ==
 
== Setup remotes to github ==
 
=== For branch trunk ===
 
=== For branch trunk ===
  cd C:\WinPython27\relax\trunk
+
<source lang="bash">
 +
  cd $relax_trunk
 +
git config --add user.name "Your Name"
 +
git config --add user.email you@example.com
 +
git config --add core.editor "nano"
 +
git config --add github.user ${GIT_USER_NAME}
 
  # If you are a member of the organization, with writing permissions, then do:
 
  # If you are a member of the organization, with writing permissions, then do:
  git remote add origin https://GIT_USER_NAME@github.com/nmr-relax/relax_trunk.git
+
  git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_trunk.git
# See the info
+
</source>
git remote -v
 
git remote show origin
 
 
 
 
Now go to github.com at https://github.com/organizations/nmr-relax click '''Repositories -> New'''.<br>
 
Now go to github.com at https://github.com/organizations/nmr-relax click '''Repositories -> New'''.<br>
 
Call it '''relax_trunk'''. We want to preserve history , so do not '''Initialize this repository with a README''' or anything like, README or .gitignore. <br>
 
Call it '''relax_trunk'''. We want to preserve history , so do not '''Initialize this repository with a README''' or anything like, README or .gitignore. <br>
  
 
Then send svn branch master of to github
 
Then send svn branch master of to github
 +
<source lang="bash">
 
  git push -u origin master
 
  git push -u origin master
 +
</source>
  
 
=== For branch relax_disp ===
 
=== For branch relax_disp ===
  cd C:\WinPython27\relax\relax_disp
+
<source lang="bash">
 +
  cd $relax_disp
 +
git config --add user.name "Your Name"
 +
git config --add user.email you@example.com
 +
git config --add core.editor "nano"
 +
git config --add github.user ${GIT_USER_NAME}
 
  # If you are a member of the organization, with writing permissions, then do:
 
  # If you are a member of the organization, with writing permissions, then do:
  git remote add origin https://GIT_USER_NAME@github.com/nmr-relax/relax_disp.git
+
  git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_disp.git
# See the info
+
</source>
git remote -v
 
git remote show origin
 
  
 
Now go to github.com at https://github.com/organizations/nmr-relax click '''Repositories -> New'''.<br>
 
Now go to github.com at https://github.com/organizations/nmr-relax click '''Repositories -> New'''.<br>
Line 94: Line 170:
  
 
Then send svn branch master of to github
 
Then send svn branch master of to github
 +
<source lang="bash">
 
  git push -u origin master
 
  git push -u origin master
 +
</source>
  
 
== git operations ==
 
== git operations ==
You may need to make a setting [http://stackoverflow.com/questions/948354/git-push-current-branch how we push branches.]
+
Get new changes from svn repository and push to github
git config push.default simple
+
git co master
 +
git svn fetch
 +
git rebase --onto remotes/git-svn
 +
git push origin master
 +
 
 +
== Saving credentials ==
 +
See [http://stackoverflow.com/questions/14629107/how-to-input-password-to-git-pull-command this post]
 +
echo "machine github.com login ${GIT_USER_NAME} password SECRET" >> ~/.netrc
 +
chmod 0600 ~/.netrc
 +
ls -la ~/.netrc
 +
cat ~/.netrc
 +
 
 +
== Setup cronjob ==
 +
Checking each 15 minutes
 +
<source lang="bash">
 +
crontab -e
 +
 
 +
# Add
 +
*/15 * * * * $HOME/backup/nmrrelax_sync_svn_git.sh
 +
</source>
 +
 
 +
== Sync script from SVN to Github ==
 +
<source lang="bash">
 +
#!/bin/bash
 +
# -*- coding: UTF-8 -*-
 +
# Script for syncing SVN to git automatically using cron.
 +
#
 +
 
 +
# exec test
 +
exec_test () {
 +
[ $? -eq 0 ] && echo "-- Command successfully executed" || echo "-- Command failed; exit 1"
 +
}
 +
 
 +
# Filenames
 +
urlhost="http://www.mail-archive.com/relax-commits@gna.org/"
 +
mydate=`date '+%Y%m%d_%H%M'`
 +
mytime=`date '+%T %Y%m%d'`
 +
 
 +
# Set paths to do the mail sync
 +
backupfolder="${HOME}/backup/nmrrelax_svn_git_sync"
 +
backupfolderurl="${backupfolder}/commit_url_dumps"
 +
dumpdate="commits_url.txt"
 +
curfile="currev.txt"
 +
prevfile="prevrev.txt"
 +
branchfile="curbranch.txt"
 +
mkdir -p $backupfolder $backupfolderurl
 +
 
 +
# Set paths to GIT
 +
relax=$HOME/backup/relax
 +
relax_trunk=${relax}/relax_trunk
 +
relax_disp=${relax}/relax_disp
 +
 
 +
# Logging
 +
exec 3>&1 4>&2
 +
trap 'exec 2>&4 1>&3' 0 1 2 3
 +
exec 1>>${backupfolder}/nmrrelax_svn_git_sync.log 2>&1
 +
# Everything below will go to the log file
 +
 
 +
dump_base () {
 +
echo "###########################"
 +
echo "STARTING on: $mytime"
 +
echo "Dumping URL webpage revisions..."
 +
#lftp -e "open ftp://${dbuser}:${dbpwd}@${dbhost} && mirror --no-perms --exclude-glob backup_scripts/ --exclude-glob cache/ --exclude-glob LocalSettings.php --parallel=10 && bye"
 +
lynx -dump $urlhost > ${backupfolderurl}/${dumpdate}
 +
currev=`grep -E '^    \* \[5\]r' ${backupfolderurl}/${dumpdate} | awk '{print $2}' | cut -c5-`
 +
branch=`grep -E '^    \* \[5\]r' -A 5 ${backupfolderurl}/${dumpdate} | grep -m 1 -e '\/branches\/relax_disp\|\/trunk'`
 +
 
 +
# Echo revision to log
 +
echo "Current revision is: $currev"
 +
# Write to current revision file
 +
echo "$currev" > ${backupfolder}/${curfile}
 +
 
 +
# Write to current branch file
 +
echo "$branch" > ${backupfolder}/${branchfile}
 +
 
 +
# Make string replacements in branch file
 +
## Replace empty spaces with nothing
 +
sed -i 's/ \+//g' ${backupfolder}/${branchfile}
 +
## Replace with relax trunk
 +
sed -i "s/.*\/trunk.*/trunk/g" ${backupfolder}/${branchfile}
 +
## Replace with relax disp
 +
sed -i "s/.*\/branches\/relax_disp.*/relax_disp/g" ${backupfolder}/${branchfile}
 +
# Set current branch from the file
 +
curbranch=`cat ${backupfolder}/${branchfile}`
 +
 
 +
# Echo branch to log
 +
echo "This is branch: $curbranch"
 +
 
 +
 
 +
# If previous revision does not exist, then create it.
 +
if [ ! -e ${backupfolder}/${prevfile} ] ; then
 +
touch ${backupfolder}/${prevfile}
 +
fi
 +
}
 +
 
 +
do_git_sync () {
 +
echo "Checking if need for for new commits ..."
 +
DIFF=`diff -q ${backupfolder}/${curfile} ${backupfolder}/${prevfile}`
 +
echo -e "Difference between current revision and current current revision is:\n${DIFF}\n"
 +
DIFFARR=($DIFF)
 +
LENDIFFARR=${#DIFFARR[@]}
 +
if [ "$LENDIFFARR" -gt "0" ]
 +
then
 +
 
 +
echo -e "#Now doing git sync for: $curbranch"
 +
echo "Changed revision to ${currev}"
 +
echo "$currev" > ${backupfolder}/${prevfile}
 +
 
 +
if [ "$curbranch" == "trunk" ]
 +
then
 +
echo "Now doing something for trunk"
 +
cd $relax_trunk
 +
git svn fetch
 +
git rebase --onto remotes/git-svn
 +
git push origin master
 +
fi
 +
 
 +
if [ "$curbranch" == "relax_disp" ]
 +
then
 +
echo "Now doing something for relax_disp"
 +
cd $relax_disp
 +
git svn fetch
 +
git rebase --onto remotes/git-svn
 +
git push origin master
 +
fi
 +
 
 +
fi
 +
}
 +
 
 +
dump_base ; exec_test
 +
do_git_sync ; exec_test
 +
 
 +
echo "Done, quit!"
 +
</source>
  
 
= See also =
 
= See also =
 
[[Category:git]]
 
[[Category:git]]
 +
[[Category:Relax]]

Latest revision as of 21:20, 21 October 2020

Caution  The information in this section is out of date but is kept for historical reasons. The relax source code is now hosted in a git rather than svn repository.

relax branches at github

You should install msysgit on windows, to do the commands.

The relax_trunk

Go to https://github.com/nmr-relax/relax_trunk
Click Fork.

Now add this as a private remote, by setting the remote name hub.

 # Windows
 set relax_trunk="C:\WinPython27\relax\relax_trunk"
 set GIT_USER_NAME="GIT_USER_NAME"
 md %relax_trunk%
 cd %relax_trunk%
 # Linux
 bash ;
 relax_trunk=$HOME/relax/relax_trunk
 GIT_USER_NAME="GIT_USER_NAME"
 mkdir -p ${relax_trunk}
 cd $relax_trunk

 git init 
 # Windows
 git remote add origin https://%GIT_USER_NAME%@github.com/nmr-relax/relax_trunk.git
 git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_trunk.git
 # Linux
 git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_trunk.git
 git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_trunk.git 

 # Or if you have setup a SSH key in github, and tested with: ssh -T git@github.com
 git remote set-url origin git@github.com:nmr-relax/relax_trunk.git
 git remote set-url hub git@github.com:${GIT_USER_NAME}/relax_trunk.git

 git fetch origin
 git checkout --track origin/master
 git fetch hub

 #Build
 scons

 ## Now we add the user scripts repo
 # Windows
 git clone https://%GIT_USER_NAME%@github.com/nmr-relax/relax_scripts.git
 # Linux
 git clone https://${GIT_USER_NAME}@github.com/nmr-relax/relax_scripts.git

Go to https://github.com/nmr-relax/relax_scripts
Click Fork.

 cd relax_scripts
 # Windows
 git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_scripts.git
 # Linux
 git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_scripts.git

The relax_disp

Go to https://github.com/nmr-relax/relax_disp
Click Fork.

Now add this as a private remote, by setting the remote name hub.

 # Windows
 set relax_disp="C:\WinPython27\relax\relax_disp"
 set GIT_USER_NAME="GIT_USER_NAME"
 md %relax_disp%
 cd %relax_disp%
 # Linux
 bash ;
 relax_disp=$HOME/relax/relax_disp
 GIT_USER_NAME="GIT_USER_NAME"
 mkdir -p ${relax_disp}
 cd $relax_disp

 git init 
 # Windows
 git remote add origin https://%GIT_USER_NAME%@github.com/nmr-relax/relax_disp.git
 git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_disp.git
 # Linux
 git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_disp.git
 git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_disp.git 

 git fetch origin
 git checkout --track origin/master
 git fetch hub

 #Build
 scons

 ## Now we add the user scripts repo
 # Windows
 git clone https://%GIT_USER_NAME%@github.com/nmr-relax/relax_scripts.git
 # Linux
 git clone https://${GIT_USER_NAME}@github.com/nmr-relax/relax_scripts.git

Go to https://github.com/nmr-relax/relax_scripts
Click Fork.

 cd relax_scripts
 # Windows
 git remote add hub https://%GIT_USER_NAME%@github.com/%GIT_USER_NAME%/relax_scripts.git
 # Linux
 git remote add hub https://${GIT_USER_NAME}@github.com/${GIT_USER_NAME}/relax_scripts.git

How the import to github was done

Based on these posts and on this recommended post, and also this post.

You need an authors.txt file, to correctly convert the metadata.

 bash ;
 relax=$HOME/backup/relax ;
 relax_trunk=${relax}/relax_trunk ;
 relax_disp=${relax}/relax_disp ;
 GIT_USER_NAME="GIT_USER_NAME" 
 mkdir -p ${relax_trunk} ${relax_disp} ;

 git svn clone http://svn.gna.org/svn/relax/trunk --no-metadata -A authors.txt ${relax_trunk} ;
 cp authors.txt ${relax_trunk} ;
 cat ${relax_trunk}/.git/config
 cp ${relax_trunk}/.git/config ${relax_trunk}/.git/config_bck
 awk '{gsub(a,b);print}' a=".*authorsfile =.*" b="        authorsfile = ${relax_trunk}/authors.txt" ${relax_trunk}/.git/config_bck > ${relax_trunk}/.git/config
 cat ${relax_trunk}/.git/config

 git svn clone http://svn.gna.org/svn/relax/branches/relax_disp --no-metadata -A authors.txt ${relax_disp} ;
 cp authors.txt ${relax_disp} ;
 cat ${relax_disp}/.git/config
 cp ${relax_disp}/.git/config ${relax_disp}/.git/config_bck
 awk '{gsub(a,b);print}' a=".*authorsfile =.*" b="        authorsfile = ${relax_disp}/authors.txt" ${relax_disp}/.git/config_bck > ${relax_disp}/.git/config
 cat ${relax_disp}/.git/config

Setup remotes to github

For branch trunk

 cd $relax_trunk
 git config --add user.name "Your Name"
 git config --add user.email you@example.com
 git config --add core.editor "nano"
 git config --add github.user ${GIT_USER_NAME}
 # If you are a member of the organization, with writing permissions, then do:
 git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_trunk.git

Now go to github.com at https://github.com/organizations/nmr-relax click Repositories -> New.
Call it relax_trunk. We want to preserve history , so do not Initialize this repository with a README or anything like, README or .gitignore.

Then send svn branch master of to github

 git push -u origin master

For branch relax_disp

 cd $relax_disp
 git config --add user.name "Your Name"
 git config --add user.email you@example.com
 git config --add core.editor "nano"
 git config --add github.user ${GIT_USER_NAME}
 # If you are a member of the organization, with writing permissions, then do:
 git remote add origin https://${GIT_USER_NAME}@github.com/nmr-relax/relax_disp.git

Now go to github.com at https://github.com/organizations/nmr-relax click Repositories -> New.
Call it relax_disp. We want to preserve history , so do not Initialize this repository with a README or anything like, README or .gitignore.

Then send svn branch master of to github

 git push -u origin master

git operations

Get new changes from svn repository and push to github

git co master
git svn fetch
git rebase --onto remotes/git-svn
git push origin master

Saving credentials

See this post

echo "machine github.com login ${GIT_USER_NAME} password SECRET" >> ~/.netrc
chmod 0600 ~/.netrc
ls -la ~/.netrc
cat ~/.netrc

Setup cronjob

Checking each 15 minutes

crontab -e

# Add
*/15 * * * * $HOME/backup/nmrrelax_sync_svn_git.sh

Sync script from SVN to Github

#!/bin/bash
# -*- coding: UTF-8 -*-
# Script for syncing SVN to git automatically using cron.
#

# exec test
exec_test () {
[ $? -eq 0 ] && echo "-- Command successfully executed" || echo "-- Command failed; exit 1"
}

# Filenames
urlhost="http://www.mail-archive.com/relax-commits@gna.org/"
mydate=`date '+%Y%m%d_%H%M'`
mytime=`date '+%T %Y%m%d'`

# Set paths to do the mail sync
backupfolder="${HOME}/backup/nmrrelax_svn_git_sync"
backupfolderurl="${backupfolder}/commit_url_dumps"
dumpdate="commits_url.txt"
curfile="currev.txt"
prevfile="prevrev.txt"
branchfile="curbranch.txt"
mkdir -p $backupfolder $backupfolderurl

# Set paths to GIT
relax=$HOME/backup/relax
relax_trunk=${relax}/relax_trunk
relax_disp=${relax}/relax_disp

# Logging
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>${backupfolder}/nmrrelax_svn_git_sync.log 2>&1
# Everything below will go to the log file

dump_base () {
echo "###########################"
echo "STARTING on: $mytime"
echo "Dumping URL webpage revisions..."
#lftp -e "open ftp://${dbuser}:${dbpwd}@${dbhost} && mirror --no-perms --exclude-glob backup_scripts/ --exclude-glob cache/ --exclude-glob LocalSettings.php --parallel=10 && bye"
lynx -dump $urlhost > ${backupfolderurl}/${dumpdate}
currev=`grep -E '^     \* \[5\]r' ${backupfolderurl}/${dumpdate} | awk '{print $2}' | cut -c5-`
branch=`grep -E '^     \* \[5\]r' -A 5 ${backupfolderurl}/${dumpdate} | grep -m 1 -e '\/branches\/relax_disp\|\/trunk'`

# Echo revision to log
echo "Current revision is: $currev"
# Write to current revision file
echo "$currev" > ${backupfolder}/${curfile}

# Write to current branch file
echo "$branch" > ${backupfolder}/${branchfile}

# Make string replacements in branch file
## Replace empty spaces with nothing
sed -i 's/ \+//g' ${backupfolder}/${branchfile}
## Replace with relax trunk
sed -i "s/.*\/trunk.*/trunk/g" ${backupfolder}/${branchfile}
## Replace with relax disp
sed -i "s/.*\/branches\/relax_disp.*/relax_disp/g" ${backupfolder}/${branchfile}
# Set current branch from the file
curbranch=`cat ${backupfolder}/${branchfile}`

# Echo branch to log
echo "This is branch: $curbranch"


# If previous revision does not exist, then create it.
if [ ! -e ${backupfolder}/${prevfile} ] ; then
touch ${backupfolder}/${prevfile}
fi
}

do_git_sync () {
echo "Checking if need for for new commits ..."
DIFF=`diff -q ${backupfolder}/${curfile} ${backupfolder}/${prevfile}`
echo -e "Difference between current revision and current current revision is:\n${DIFF}\n"
DIFFARR=($DIFF)
LENDIFFARR=${#DIFFARR[@]}
if [ "$LENDIFFARR" -gt "0" ]
then

echo -e "#Now doing git sync for: $curbranch"
echo "Changed revision to ${currev}"
echo "$currev" > ${backupfolder}/${prevfile}

if [ "$curbranch" == "trunk" ]
then
echo "Now doing something for trunk"
cd $relax_trunk
git svn fetch
git rebase --onto remotes/git-svn
git push origin master
fi

if [ "$curbranch" == "relax_disp" ]
then
echo "Now doing something for relax_disp"
cd $relax_disp
git svn fetch
git rebase --onto remotes/git-svn
git push origin master
fi

fi
}

dump_base ; exec_test
do_git_sync ; exec_test

echo "Done, quit!"

See also