Git GUI Tools

I recently found about gui tools for git. I knew about gitk and merge tools but was not aware there was a gui that could help you remember or explain some of the concepts of git one use daily. The gui can be started from the cli:

$ git gui

And it will show you something like:

I tested it on the following task. I had to filter the changes done in certain files. I had affected some of the core files where it was unacceptable and other core files where my changes were meant to be. I had to first rebase and squash all my commits with:

git rebase -i HEAD~2
// then set to `s` the commits

Then I would proceed with the `gui` tools to select ammend last commit, and could remove the hunks/changes made to certain core files. Thereby I cleaned/filtered all my commits while I was squashing them. This could have been a nightmare or longer process without the gui tools.
If say I have had the need to enter some changes I could have commit my change and then squash and follow the same pattern of operations.

Hope this helps!

Grace is Not Receiving The Lethal Injection

I have heard some comments about what happened with Troy Davis. Whether this man is innocent or not some people is disputing more the death row penalty rather than what actually happened or the judgement wrong or right.

In this background Grace meant not receiving the lethal injection. Troy perhaps did or did not deserved it. But unfortunately he was killed without a judgement of perfection. Judgement is flaw and certainly one can argue that. However there is a judgement for Troy and moreover on us that is perfect. That ladies and gentlemen is the judgement of God pure and righteous. This judgement brings God’s wrath on all of us justly. There is but one escape and it is found in grace. And grace only flows from a single human-God person, Jesus Christ. If you are not in Him, you certainly fall with everybody else and whether or not you agree or disagree with Troy’s death you deserve, no matter how good your good morals and behavior are, a life sentence of lethal injection, lethal wrath abiding starting since the beginning.

Grace objects then are so much fortunate! Come to Christ!

Beyond Compare Git Mergetool Settings

From their website:

Diff

Create a shell script file “git-diff-wrapper.sh” with the following content:

  #!/bin/sh
  # diff is called by git with 7 parameters:
  # path old-file old-hex old-mode new-file new-hex new-mode
  "<path_to_bc3_executable>" "$2" "$5" | cat

In a console window enter the command:

  $ git config --global diff.external <path_to_wrapper_script>

3-way Merge (v3 Pro)

In a console window enter the following three commands:

  $ git config --global merge.tool bc3
  $ git config --global mergetool.bc3.cmd "/usr/bin/bcompare \$LOCAL
    \$REMOTE \$BASE \$MERGED"
  $ git config --global mergetool.bc3.trustExitCode true

2-way Merge (v3 Std, v2)

In a console window enter the following three commands:

  $ git config --global merge.tool bc3
  $ git config --global mergetool.bc3.cmd "/usr/bin/bcompare \$LOCAL
    \$REMOTE -savetarget=\$MERGED"
  $ git config --global mergetool.bc3.trustExitCode true

PHPSpec Advance

This post is inspired in the development here.

I received great help from jbohn.

So we are starting according to certain scenario.

Feature: Member rents video
  As a video-club member
  I want to rent a video
  So that I can take it away with me and watch it conveniently at home
 
Feature: Members rents video
  As a video-club member
  I want to rent a video
  So that I can take it away with me and watch it conveniently at home
 
  Scenario: Renting single video from oldies section
    Given I am in the "review" page
      And the selected video is "Revolution OS"
     When I click on "Rent"
     Then "£2" is added to my total
 
  Scenario: Renting 3 videos from oldies promotion
    Given I am in the "review" page
      And "Revolution OS" is selected
      And "Blade Runner" is selected
      And "The Wall" is selected
     When I click on "Rent"
     Then "£5" is added to my total

Then we run behat on the file and we are getting:

There is an error with the view already. The reason why we have passed the first step is only because there is already a router for the framework and debugging enabled. However the page that is gotten back by the step is not really a valid page. Once we are at this point we go deeper into the PHPSpec cycle now.

We run the following command because phpspec installed via pear is not the one we are using. Why? Because it does not have knowledge of our updates and also it does not have knowledge of our third party libraries, and also because we want to have full control on what gets loaded. I ran into a redefine issue with function any() conflict between phpunit and hamcrest library.

So here is the command I use:

~/sites-2/FormModelProjectBundle (phpspec) vendor/phpspec/scripts/phpspec.php vendor/bundles/Cordova/Bundle/FormModelBundle/

The `phpspec` script is smart enough to look for the right Spec folder under the bundle and runs the phpspec for IndexSpec.php which is made locatable because of its Spec.php ending.

The resulting output of the previous command is:

E
Exceptions:
 
  1) Cordova\Bundle\FormModelBundle\Specs\views\Index renders the selected video
     Failure\Exception: $this->runExamples($exampleGroup, $reporter);
     InvalidArgumentException: Unable to find template "CordovaFormModelBundle:index.html.twig".
 
Finished in 0.134287 seconds
1 example, 1 exception

Notice here that it tells us that we have the wrong path for our template. Which theoretically is unimplemented. The exact error means that we actually need to insert the logical controller name between the ::. This is familiar to sf2 developers. So we do the change and having a lame default controller we have now the following error:

F
 
Failures:
 
  1) Cordova\Bundle\FormModelBundle\Specs\views\Index renders the selected video
     Failure\Error: $output->should->contain('Revolution OS');
     expected to contain 'Revolution OS', found no match (using contain())
     # ./vendor/bundles/Cordova/Bundle/FormModelBundle/Specs/views/IndexSpec.php:16

Finished in 1.080713 seconds
1 example, 1 failure

Notice: we could have used the generation of a bundle. However since controllers are mostly custom code then there is no point really in using generator unless it is a new action to be placed in a new bundle. So there is no need in sf2 to use a generation command here unless in the case where we are putting things into a new bundle. For all other cases we just copy/paste a controller common template.

Now we know where all our efforts must concentrate, namely here $output->should->contain('Revolution OS');. This means the template rendered has nowhere the label `Revolution OS`. The major problem here is that we need to work on the loading of matchers for Symfony2.

Once we worked on the matcher `Contain` we can run the phpspec command again and we get:

vendor/phpspec/scripts/phpspec.php vendor/bundles/Cordova/Bundle/FormModelBundle/Specs/views/IndexSpec.php
.
 
Finished in 1.029784 seconds
1 example

Now we are ready to head onto developing the C standing for the controller layer. The controller basically is in charge of doing the dispatching of things. So we need to work again on the Symfony2 controller version of things.

<?php
 
class DescribeIndex extends View
{
    function itRendersTheSelectedVideo()
    {
        $video = \Mockery::mock(
            'Application_Model_Video', array('getName' => 'Revolution OS'));
 
        $output = $this->render('MyBundle:Video:detail.html.twig', array(
            'video' => $video,
        );
        $output->should->contain('Revolution OS');
    }
}
<?php
 
use PHPSpec\Context;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
 
class View extends Context
{
    private $engine;
 
    public function setTemplatingEngine(EngineInterface $engine)
    {
        $this->engine = $engine;
    }
 
    public function spec()
    {
        $interceptor = call_user_func_array(
            array(
            '\PHPSpec\Specification\Interceptor\InterceptorFactory',
            'create'), func_get_args()
        );
 
        $interceptor->addMatchers(array('contain', 'haveSelector'));
        return $interceptor;
    }
 
    public function render($template, array $templateContext = array())
    {
        if (is_null($this->engine)) {
            throw new \LogicException('No templating engine set.');
        }
 
        return $this->spec($this->engine->render($template, $templateContext));
    }
 
}

Multi-Contextualization For Behat

The seed for the concept of multi-contextualization was stated in an earlier post here. This idea although perhaps not compatible with the initial intent of Behat is in high use for real life application development.
There was a recent post on stackoverflow about this to which a developer @takeshi answered in a very interesting way:

Use class inheritance and separate contexts.
 
# /features/contexts/
AbstractContext extends BehatContext {}
FeaturenameContext extends AbstractContext {}
Then in /feature/FeatureContext.php import the context files:
 
/**
 * Initializes context.
 * Every scenario gets it's own context object.
 *
 * @param array $parameters context parameters (set up via behat.yml)
 */
public function __construct(array $parameters) {
 
    // import all context classes from context directory, except the abstract one
 
    $filesToSkip = array('AbstractContext.php');
 
    $path = dirname(__FILE__) . '/../contexts/';
    $it = new RecursiveDirectoryIterator($path);
    /** @var $file  SplFileInfo */
    foreach ($it as $file) {
        if (!$file->isDir()) {
           $name = $file->getFilename();
           if (!in_array($name, $filesToSkip)) {
               $class = pathinfo($name, PATHINFO_FILENAME);
               require_once dirname(__FILE__) . '/../context/' . $name;
               $this->useContext($class, new $class($parameters));
           }
        }
    }
}

Here I would like to highlight not the use of inheritance because I prefer sub-contextualization as I had explained in an earlier post, but rather I would like to highlight the alternative mechanism to load a specific context. This is very important as is one earlier effort for multi-contextualization for Behat. I hope more development is done in this branch. If not I think this one is going to be an open opportunity for development in the near future. @TODO

WordPress Plugin Deploying From Github To SVN

I am writing this post mainly to document my steps of deploying to svn from github.
Most of the tips are taken from this post.
However I want to note and add that the last commands need to be iterated while developing. Another important thing is to have both repos synced so if you went one way with one and the other way with another and you are trying to commit then it is a waste of time and you will get tons of errors. Once you sync them and then you push to your git repo from your local and rewind things then it would work.

git clone git@github.com:cordoval/wp-sf2.git wp-sf2
cd wp-sf2/
svn log --limit 1 http://plugins.svn.wordpress.org/wp-sf2
------------------------------------------------------------------------
r434169 | cordoval | 2011-09-06 11:20:43 -0500 (Tue, 06 Sep 2011) | 1 line
 
added image
------------------------------------------------------------------------
git svn init --trunk=trunk --branches=branches --tags=tags http://plugins.svn.wordpress.org/wp-sf2
git svn fetch -r434169
git branch
* master
git branch -r
  origin/HEAD -> origin/master
  origin/master
  trunk
echo `git log --pretty=oneline master | tail -n1 | cut -d ' ' -f 1` `git show-ref trunk | cut -d ' ' -f 1` >> .git/info/grafts

Notice: Once you want to sync both repos back to the github repo you have to remove the graft file in order to push origin master.

Prototype attribute on Symfony2 Forms

This is a snippet for collaboration purposes on dynamic forms:

<div id="khepin_productbundle_producttype_tags" data-prototype="
 
<label  class="">$$name$$</label>
<div id="khepin_productbundle_producttype_tags_$$name$$">
  <label for="khepin_productbundle_producttype_tags_$$name$$_name" class="">Name</label>
  <input type="text" id="khepin_productbundle_producttype_tags_$$name$$_name" name="khepin_productbundle_producttype[tags][$$name$$][name]" required="required" maxlength="255" value="" class="input-text" />
</div>
 
"></div>

Here it is sbsien :)

Also please fix the css if you can.

PS> All this is regarding this link

Specto + Symfony 2 + Git

If you install specto following these instructions and not from the ubuntu software center repository then you will be getting the latest version:

http://code.google.com/p/specto/wiki/Installing

Then set up a feed subscription on reader.google.com the service that is supported nicely by specto. Set this name label into your specto and you will get notifications of pushes into the central git repository be github or other rss commit url.

This will be good to communicate across team members.