Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Wednesday, March 21, 2012

Version numbers on software with git, tags and sed

After I moved from svn to git, I started doing some version numbers manually, as I felt I never had the time to figure out a good way to set version numbers using git. However, it's much easier and simpler than in svn, when done right.

Usually I use version numbers like this: 1.0.290, where 1 is major, 0 is minor and 290 the revision number.

I wanted to keep the same pattern when using git, as a lot of the software I maintain is moved from svn, where the revision was used directly from the svn repository.

Instead of having automatic revision numbers, I'm only going to increase them when I want to. That makes it possible to commit without increasing the revision number, which is really want I wanted to do.

Here's a quick and simple way to do it:
Tag your repository v1.0.290 (or similar)

To get the major, minor and revision number, git hash and number of commits since that tag:

echo "major:"
git describe --tags --long | sed "s/v\([0-9]*\).*/\1/"

echo "minor:"
git describe --tags --long | sed "s/v[0-9]*\.\([0-9]*\).*/\1/"

echo "revision:"
git describe --tags --long | sed "s/v[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/"

echo "commits since tag:"
git describe --tags --long | sed "s/v[0-9]*\.[0-9]*\.[0-9]*-\([0-9]*\).*/\1/"

echo "git_hash:"
git describe --tags --long | sed "s/v[0-9]*\.[0-9]*\.[0-9]*-[0-9]*-g\(.*\)/\1/"

It should give an idea on how to get the data needed to update a project with the corresponding version info.

Friday, February 3, 2012

Convert from svn to git

Time to convert all those old SVN repositories to GIT... I'm using bitbucket for everything now.. On ubuntu do "apt-get install git git-svn" first

Short script to do it all: (it's not perfect, but it does the job...)

#!/bin/bash
# variables:
# existing svn repository
SVNREPO=$1
# new git repository
GITREPO=$2
# username
# SVNUSERNAME=$3

# DO THIS FIRST TO CREATE USERLIST: (just do it manually, and add all users into one big file)
# for getting authors
# svn log $SVNREPO -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" quot;, "", $2); print $2" = "$2" <"$2">"}' | sort -u > ~/svn_convert/authors-transform.txt
#now edit ~/svn_convert/autors-transform.txt

#create temporary git folder
mkdir git_tmp_repo
cd git_tmp_repo
#clone repo to git
git svn clone --no-metadata -A ~/svn_convert/authors-transform.txt . -T $SVNREPO

#optimize repo
git gc
git fsck

# clean SVN sections from Git
git config --remove-section svn
git config --remove-section svn-remote.svn
rm -rf .git/svn .git/{logs/,}refs/remotes/svn/

# add remote
git remote add origin $GITREPO

# push to master
git push -u origin master

# remove temporary git folder

cd ..
rm -rf git_tmp_repo