Skip to content

Commit

Permalink
[Twenga#118] Adding version info to Twgit Tool
Browse files Browse the repository at this point in the history
The version info will look for every files specified in the
TWGIT_VERSION_INFO_PATH to replace Id tag with starting new tag.
The Id tag has to be written either as '$Id$' or '$Id:1.2.3'
When beginning a new tag (twgit init, twgit release start or
twgit hotfix start), the value will be updated with new version
information (ex. $Id:1.3.0$).

Specific tests have been written to check that waited and
unwaited substitution are correctly performed for the three way
of starting a new tag.
  • Loading branch information
Sebastien-Hanicotte committed Nov 22, 2013
1 parent 1402b4e commit 65a505a
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
7 changes: 7 additions & 0 deletions conf/twgit-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ TWGIT_FEATURE_SUBJECT_REDMINE_DOMAIN='' # e.g. 'www.redmine.org', with optional
TWGIT_FEATURE_SUBJECT_GITHUB_USER='' # e.g. 'Twenga'
TWGIT_FEATURE_SUBJECT_GITHUB_REPOSITORY='' # e.g. 'twgit'

# All the files designed in the TWGIT_VERSION_INFO_PATH list will be
# parsed in order to search for $Id$ or $Id:#.#.#$ and replace with
# the current version (ex. being in v1.2.3 and calling twgit release start
# will result in replacing all results with $Id:1.3.0$
# /!\ File list is comma separated : TWGIT_VERSION_INFO_PATH='file1.php,file2.php'
TWGIT_VERSION_INFO_PATH=''

##
# Colors and decorations types.
# MUST define following types:
Expand Down
29 changes: 29 additions & 0 deletions inc/common.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,9 @@ function init () {
git commit -m 'Add minimal .gitignore' || die 'Add minimal .gitignore failed!'
exec_git_command "git push $TWGIT_ORIGIN $TWGIT_STABLE" "Add minimal .gitignore failed!"
fi
update_version_information "$tag"
create_and_push_tag "$tag_fullname" "First tag."
}
Expand Down Expand Up @@ -1529,6 +1532,32 @@ function clean_prefixes () {
fi
}
##
# This function permits to store the version information inside files designed
# in a global variable TWGIT_VERSION_INFO_PATH defined in some config file as
# .twgit on conf/twgit.sh
#
# @param string $version Is the current version 'started' (with Hotfix and/or
# Release and/or Init)
#
function update_version_information()
{
local version="$1"
CUI_displayMsg processing 'Testing the parameter TWGIT_VERSION_INFO_PATH...'
if [[ ! -z $TWGIT_VERSION_INFO_PATH ]]; then
CUI_displayMsg processing 'Parameter not null (coool yeah !?)...'
for filepath in $(echo $TWGIT_VERSION_INFO_PATH | tr ',' ' '); do
CUI_displayMsg processing 'Found 1 path '$filepath'...'
if [[ -f $filepath ]]; then
CUI_displayMsg processing 'File existed executing sed...'
sed -i 's/\$Id[:v0-9\.]*\$/$Id:'$version'$/' "$filepath"
exec_git_command "git add $filepath" "Could not add version info!"
fi
done
fi;
}
##
# Permet la mise à jour automatique de l'application dans le cas où le .git est toujours présent.
# Tous les $TWGIT_UPDATE_NB_DAYS jours un fetch sera exécuté afin de proposer à l'utilisateur une
Expand Down
3 changes: 3 additions & 0 deletions inc/twgit_hotfix.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function cmd_start () {
hotfix=$(get_next_version 'revision')
local hotfix_fullname="$TWGIT_PREFIX_HOTFIX$hotfix"
exec_git_command "git checkout -b $hotfix_fullname tags/$last_tag" "Could not check out tag '$last_tag'!"

update_version_information "$hotfix"

process_first_commit 'hotfix' "$hotfix_fullname"
process_push_branch $hotfix_fullname
else
Expand Down
3 changes: 3 additions & 0 deletions inc/twgit_release.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ function cmd_start () {
else
local last_tag=$(get_last_tag)
exec_git_command "git checkout -b $release_fullname tags/$last_tag" "Could not check out tag '$last_tag'!"

update_version_information "$release"

process_first_commit 'release' "$release_fullname"
process_push_branch $release_fullname
fi
Expand Down
27 changes: 27 additions & 0 deletions tests/TwgitFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,32 @@ public function testWhatChanged_WithPrefixes ()
$sMsg = $this->_localExec(TWGIT_EXEC . ' feature what-changed feature-42');
$this->assertContains("Assume feature was '42' instead of 'feature-42'", $sMsg);
}

public function testStartWithVersionInfo ()
{
$this->_remoteExec('git init');
$this->_localExec(TWGIT_EXEC . ' init 1.2.3 ' . TWGIT_REPOSITORY_ORIGIN_DIR);
$this->_localExec(TWGIT_EXEC . ' feature start 42');
$this->_localExec('echo "TWGIT_VERSION_INFO_PATH=\'test.php\'" >> .twgit');
$this->_localExec('echo "<?php" > test.php');
$this->_localExec('echo "\$maVersion = \'\$Id\$\';" >> test.php');
$this->_localExec('echo "\$maVersion2 = \'\$Id:1.2.3\$\';" >> test.php');
$this->_localExec('echo "\$maVersion3 = \'\$id\$\';" >> test.php');
$this->_localExec('echo "echo \$maVersion . \$maVersion2 . \$maVersion3;" >> test.php');
$this->_localExec('cp test.php test2.php');
$this->_localExec('git add .');
$this->_localExec('git commit -m "Adding testing files"');
$this->_localExec(TWGIT_EXEC . ' release start -I');
$this->_localExec(TWGIT_EXEC . ' feature merge-into-release 42');
$this->_localExec(TWGIT_EXEC . ' release finish -I');
$this->_localExec(TWGIT_EXEC . ' release start -I');
$sMsg = $this->_localExec('php test.php');
$sMsg2 = $this->_localExec('php test2.php');
/**
* Testing init $Id$, former $Id$ and bad written $id$
*/
$this->assertContains('$Id:1.4.0$$Id:1.4.0$$id$', $sMsg);
$this->assertContains('$Id$$Id:1.2.3$$id$', $sMsg2);
}
}

27 changes: 27 additions & 0 deletions tests/TwgitHotfixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,33 @@ public function testRemove_WithExtraCommitIntoStableThenReset ()
$this->assertContains('v1.2.4', $sMsg);
}

public function testStartWithVersionInfo ()
{
$this->_remoteExec('git init');
$this->_localExec(TWGIT_EXEC . ' init 1.2.3 ' . TWGIT_REPOSITORY_ORIGIN_DIR);
$this->_localExec(TWGIT_EXEC . ' feature start 42');
$this->_localExec('echo "TWGIT_VERSION_INFO_PATH=\'test.php\'" >> .twgit');
$this->_localExec('echo "<?php" > test.php');
$this->_localExec('echo "\$maVersion = \'\$Id\$\';" >> test.php');
$this->_localExec('echo "\$maVersion2 = \'\$Id:1.2.3\$\';" >> test.php');
$this->_localExec('echo "\$maVersion3 = \'\$id\$\';" >> test.php');
$this->_localExec('echo "echo \$maVersion . \$maVersion2 . \$maVersion3;" >> test.php');
$this->_localExec('cp test.php test2.php');
$this->_localExec('git add .');
$this->_localExec('git commit -m "Adding testing files"');
$this->_localExec(TWGIT_EXEC . ' release start -I');
$this->_localExec(TWGIT_EXEC . ' feature merge-into-release 42');
$this->_localExec(TWGIT_EXEC . ' release finish -I');
$this->_localExec(TWGIT_EXEC . ' hotfix start -I');
$sMsg = $this->_localExec('php test.php');
$sMsg2 = $this->_localExec('php test2.php');
/**
* Testing init $Id$, former $Id$ and bad written $id$
*/
$this->assertContains('$Id:1.3.1$$Id:1.3.1$$id$', $sMsg);
$this->assertContains('$Id$$Id:1.2.3$$id$', $sMsg2);
}

/**
* @dataProvider providerTestListAboutBranchesOutOfProcess
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/TwgitMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ public function testInit_WithRemoteStable ()
$this->assertContains('git tag -a v1.2.3 -m "[twgit] First tag."', $sMsg);
}

public function testInit_WithVersionInfo ()
{
$this->_remoteExec('git init');
$this->_localExec('git init');
$this->_localExec('echo "TWGIT_VERSION_INFO_PATH=\'test.php\'" >> .twgit');
$this->_localExec('echo "<?php" > test.php');
$this->_localExec('echo "\$maVersion = \'\$Id\$\';" >> test.php');
$this->_localExec('echo "\$maVersion2 = \'\$Id:1.0.2\$\';" >> test.php');
$this->_localExec('echo "\$maVersion3 = \'\$id\$\';" >> test.php');
$this->_localExec('echo "echo \$maVersion . \$maVersion2 . \$maVersion3;" >> test.php');
$this->_localExec('cp test.php test2.php');
$this->_localExec('git add .');
$this->_localExec('git commit -m "Adding testing files"');
$this->_localExec(TWGIT_EXEC . ' init 1.2.3 ' . TWGIT_REPOSITORY_ORIGIN_DIR);
$sMsg = $this->_localExec('php test.php');
$sMsg2 = $this->_localExec('php test2.php');
/**
* Testing init $Id$, former $Id$ and bad written $id$
*/
$this->assertContains('$Id:1.2.3$$Id:1.2.3$$id$', $sMsg);
$this->assertContains('$Id$$Id:1.0.2$$id$', $sMsg2);
}

/**
* @dataProvider providerTestGetContributors_WithOnly1Author
* @shcovers inc/common.inc.sh::get_contributors
Expand Down

0 comments on commit 65a505a

Please sign in to comment.