Blogs

git Integration Manager Workflow tutorial

 

IN BLESSED

mkdir gitlab/blessedrepo

cd gitlab/blessedrepo

git init

 

Creating new files:

vim README

adding:

git add .

git commit -m "first file in blessed repository"

git push

 

IN DEVELOPERS

mkdir developer2

cd developer2

git clone /Users/air/gitlab/blessedrepo

ls

blessedrepo

ls blessedrepo/

README

cd blessedrepo

vim fileindev2.html

git add .

 

 

MacBook-Air-de-Air:blessedrepo air$ git commit -m "added file by developer2"

[master 422f2e5] added file by developer2

 1 file changed, 2 insertions(+)

 create mode 100644 fileindev2.html

MacBook-Air-de-Air:blessedrepo air$ 

 

 

get changes from main repository:

 

MacBook-Air-de-Air:blessedrepo air$ git pull

Already up-to-date.

MacBook-Air-de-Air:blessedrepo air$

 

 

Getting changes from a developer. In Blessedrepository, we execute:

 

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

.git/                 fileindev2.html       thirdfileindev1.html  

README                secondfile.html       

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

remote: Counting objects: 4, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Updating d3bb3f1..422f2e5

Fast-forward

 fileindev2.html | 2 ++

 1 file changed, 2 insertions(+)

 create mode 100644 fileindev2.html

MacBook-Air-de-Air:blessedrepo air$

 

 

Now, Blessedrepository has the new files:

 

MacBook-Air-de-Air:blessedrepo air$ ls

README secondfile.html

fileindev2.html thirdfileindev1.html

MacBook-Air-de-Air:blessedrepo air$ 

Now, developer1 wants to get changes in main Repository:
MacBook-Air-de-Air:blessedrepo air$ git pull
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /Users/air/gitlab/developer1/publicrepo/../../blessedrepo
   21f5117..422f2e5  master     -> origin/master
Updating d3bb3f1..422f2e5
Fast-forward
 fileindev2.html | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 fileindev2.html
MacBook-Air-de-Air:blessedrepo air$

 

Now, test conflicts. dev 1 and dev2 edit the same file, 

 

 

MacBook-Air-de-Air:blessedrepo air$ git add .

MacBook-Air-de-Air:blessedrepo air$ git commit -m "added by dev1"

[master 80f7afa] added by dev1

 Committer: Air <air@MacBook-Air-de-Air.local>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:


    git config --global user.name "Your Name"

    git config --global user.email you@example.com


After doing this, you may fix the identity used for this commit with:


    git commit --amend --reset-author


 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 


 

 

Developer 2, the same:

 

 

MacBook-Air-de-Air:blessedrepo air$ git add 

Nothing specified, nothing added.

Maybe you wanted to say 'git add .'?

MacBook-Air-de-Air:blessedrepo air$ git add .

MacBook-Air-de-Air:blessedrepo air$ git commit -m "changes by dev2 in same file"

[master 20b26a8] changes by dev2 in same file

 Committer: Air <air@MacBook-Air-de-Air.local>

    git commit --amend --reset-author

 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 

 

Time to pull changes from developer1 and 2 in Blessed Repository:

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Already up-to-date.

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Updating 422f2e5..20b26a8

Fast-forward

 secondfile.html | 2 ++

 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 

 

and from the other developer (where we expect the conflict):

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer1/publicrepo/blessedrepo/

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer1/publicrepo/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Auto-merging secondfile.html

CONFLICT (content): Merge conflict in secondfile.html

Automatic merge failed; fix conflicts and then commit the result.

MacBook-Air-de-Air:blessedrepo air$ 

 

 

RESOLVE CONFLICTS

git mergetool

 

 

 

categorias: 

private git repositories in bitbucket

Let me got directly to the point. The bitbucket documentation is wrong, on the begining you are just suposed to do a git remote add origin

in the directory which you want to commit. But this will not work:

fatal: Not a git repository (or any of the parent directories): .git

Solution? Init the repository:

git init

git remote add origin https://ACCOUNT@bitbucket.org/ACCOUNT/REPOSITORY.git

git push -u origin master

will also don´t work :-(. The problem is that the message error is all but obvious.

 

error: src refspec master does not match any.

error: failed to push some refs to 'https://ACCOUNT@bitbucket.org/ACCOUNT/REPOSITORY.git'

 

But, think... we need to have something to commit before sending this "thing", don't we?

Then:

git add .

git commit -m "first commit with all the contents

And, finally, we send the commits with the changes in our code:

git push -u origin master

 

remote: bb/acl: hispamedios is allowed. accepted payload.

To ....

 

Nice, isn't it?

categorias: 

Theming you module

Docs are not allways the best part in programming languages, frameworks or CMS. Sometimes you try to make something and you find problems, just because poor documentation.

It's my situation just now. I was trying to create tpl.php files for a module, and it is really easy... if you follow exactly all the steps.

First, hook_menu:

 

 

/**

 * Implements hook_menu().

 */

function mymodule_menu() {

$items = array();

 

/*

* Category reviews section 

*/

$items['reviews'] = array(

'title'             => 'Bounty reviews',

'description'       => 'Show review categories.',

'page callback'     => 'listofProducts',

  'page arguments'    => array('bounty_settings'),

'access callback'   => 'user_access',

'access arguments'  => array('administer site configuration'),

'type'              => MENU_NORMAL_ITEM,

'file'              => 'includes/bounty_reviews.inc',

);

 

return $items;

}

 

 

Secondly, you could think that just creating the listofProducts should be enought. Well, not at all, you need the theme hook, to show the content using the tpl.php of you choose:

 

/**

 * Implements hook_theme().

 */

function mymodule_theme($existing, $type, $theme, $path){

$path = drupal_get_path('module', 'mymodule'); // . '/templates';

// ADD THE templates DIRECTORY

$path = $path . '/templates'; 

return array(

// as in 'theme('verbose_method',...)

'main_reviews' => array(

'template' => 'main_page_reviews',

'path' => $path,

'variables' => array('forums' => NULL, 'topics' => NULL,'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),

),

//...

);

}

 

And, ending with the magic:

 

/**

 * List of  reviewable products

 *

 */

function listofProducts(){

$output = theme('list_products');

return $output;

}

That's all. If you forget the _theme hook you can be struggling for hours, just receiving a beauty WSOD (White Screen Of the Death) and no more information.

You wellcome :-).

 

Solving error 500 in Symfony2

Having the typical error 500 in Symfony2? Well, it is very tipical, not just in Symfony but in Drupal and other web frameworks and CMS. Solving it can be a big headache... if you don't know where to see.

In Drupal it is easy to solve it using show all errors in php (on index.php of Drupal, for example). In Symfony2 you can use this tip:

Go to the root of your app. Then execute a clean cache:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }php app/console cache:clear{/syntaxhighlighter}What we achieve with that is being able to see error messages on console, after you execute this command. Messages that you will not allways see en error.logs of apache or ngnix.

categorias: 

Symfony2: Not a git repository

Ok, you want to install a bundly in Symfony2, and you are going to use git. You go to your root directory... but, here is the problem

Command:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }git submodule add git://github.com/simplepie/simplepie.git vendor/simplepie{/syntaxhighlighter}

Yes, it's Simplepie bundles for Symfony2. Ok, the error:

 

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }fatal: Not a git repository (or any of the parent directories): .git{/syntaxhighlighter}

It's quite simple. You don't have initialized git:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }$git init
> Initialized empty Git repository in /var/www/symlabs/[project]/.git/
{/syntaxhighlighter}

Try again and... Yes, you welcome :-)

 

categorias: 

Minimal Apache2 modules for Drupal

This days i've been having problems with my server, until i arrived to a point on I was considering seriously disable Apache and install ngnix, a light server I am using in my laptop and some small projects.

The point is that I don't have noticed a real big performance increment in my laptop (difficult with a few users). Anyway, having to install a new server, disable Apache, tuning everything to work correctly is a good challenge... unless you are at the doors of taking a plane and don't want to be all the trip thinking about the server...

Solution? Ok, let's tuning the Apache2 server, very easy because where are only going to use a2dismod to disable the modules and a2enmod to activate if they give us some error... Easy, right?

Let's go, this is my minimal (by now) apache modules list:

actions.conf  alias.conf  authn_file.load authz_host.load  dir.load    fcgid.load  mime.load  php5.load  suexec.load

actions.load  alias.load  authz_groupfile.load dir.conf fcgid.conf  mime.conf php5.conf  rewrite.load

You can disable the rest with a2dismod [MODULENAME], for example:

a2dismod cgi

I recommend you to restart your server once disabled. If apache cannot restart, enable the module again with a2enmod [MODULENAME] and try again the restart.

I have to say that last week I've been having a lot of problems... The last thing I did was to tune in that way Apache... and simply magic, sites load incredibly fast with this simply modification.

Now, I can fly withour worries :-).

categorias: 

Fatal error: require_once() [function.require]: Failed opening required sites/all/ modules/feeds_xpathparser/ FeedsXPathParser

After installing all the updates and changing the core of drupal (main files), you could find this error doing the upgrade (opening upgrade.php).

It's a problem specified here: http://drupal.org/node/868532

Well, simply disable the feeds modules, all, ignore by now the errors and proceed with the upgrade. No errors, right?

You can now put again your website online and proceed to solve the problem (previous link) with feeds, with without having to wait to your users :-).

categorias: 

Error 500 in Drupal (invite module)

Error 500 in your Drupal? Don't panic.... well, a little maybe, but be sure you'll find a way to solve it.

open your index.php in root Drupal and add:

error_reporting(E_ALL);

ini_set('display_errors', '1');

Reload the Error 500 page and, evoilá:

Fatal error: Call to undefined function invite_page_title() in /[.....]/httpdocs/includes/menu.inc on line 

This is saying that there is a problem with a module. In my case, I disabled invite, and seems to cause problems. Before the show php errors trick I was blind, but I disabled several modules and started to have problems, so I had no way to know which one were giving us problems and, so the, how to solve it.

Ok, if this is the scenario (not able to even login in your site to disable modules), then drush is simply magic. Install it and:

drush --uri=website.com enable invite

try now. If the error persists, it is probably that it has changed and now it shows you another module or another kind of problem. That's is, then, another story :-).

Sometimes you'll need to clear your cache or make some other operations, only availabe via admin interface... well, not exactly, drush also can help you, for example, with a "clean drush" For more information visit: http://groups.drupal.org/node/28088

categorias: 

Zend php framework quickstart howto (ubuntu + nginx)

Those days i've been playing with the so known and symfony competence, Zend framework, and the basic installation in ngnix.

I have to say that I love all this php frameworks, and the ruby idea of using the command line.

In ubuntu, installing zend to begin is as easy as:

sudo apt-get install zend-framework

And that's it, you have Zend installed in your machine.... don't believe me?? Create and go to /var/www/zend directory. Inside type: 

zf create project tutorial

Ready.... well, okay, not 100%, you still have to say to your server (apache or nginx in my case) where the project is.

I like to have urls for each project, as if they were living in different servers, so I added a new host in my /etc/hosts file:

127.0.1.1       zend

and, in /etc/nginx/sites-enabled/default-zend you'll finally have to add:

 

 

server {

      listen 80;

      server_name zend;

      root /var/www/zendlab/tutorial/public; ## <-- Your only path reference.

      index  index.html index.htm index.php;

        location / {

                try_files $uri $uri/ /index.php;

        }

        location ~ \.php$ {

    try_files       $uri /index.php;

    fastcgi_index   index.php;

    fastcgi_pass    127.0.0.1:9000;

    include         fastcgi_params;

    fastcgi_param   SCRIPT_FILENAME  /var/www/zendlab/tutorial/public$fastcgi_script_name;

    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

        }

}

 

 

And you finally can load your new Zend project from: http://zend/

Beauty solution, isn't it?

Well, we have Zend working, but it still doesn't do too much. Let's create our firs controller:

zf create action add Index

One thing which i've liked about Zend. It automatically suposes that you will use PHPUnit:

Note: PHPUnit is required in order to generate controller test stubs.

 

Refactoring

the steps in refactoring, from the book: "Refactoring: Improving the Design of Existing Code" by Martin Fowler:

  • Identify the code in need of refactoring.
  • Have test coverage for the code.
  • Work in small steps.
  • Run your tests after each step. Code and test in quick iterations — which is much easier
  • in an interpreted language like PHP as compared with compiled languages.
  • Use refactoring to make your more readable and to improve performance.
categorias: