Donnerstag, 31. März 2016

Creating a patch by Git

Firstly create a new Git branch: 

git checkout -b my-new-branch

Do your changes and commit:

git commit -am "My changes."
Now create the patch file by a diff from your branch and the development branch (f.e. master or develop):

git format-patch master --stdout > fix_empty_poster.patch 
Afterwards you can switch into a different branch, where you want to apply the patch file.

git checkout master

To check if the patch can be applied, use the following command:

git apply --check fix_empty_poster.patch 
To check which impact the patch will have, use the following command:

git apply --stat fix_empty_poster.patch
You can also apply the patch by

git apply < fix_empty_poster.patch

But this command will not create a Git commit by one action.

For applying the patch, use the following command:

git am --signoff < fix_empty_poster.patch 
 By this command, the patch will be already commited into Git. So you'll the the following entry in your Git log, if you type

git log

commit 2839f6f8e408140956d121b2af28b55543e93ec0
Author: Peter
Date:   Wed Mar 30 21:04:21 2016 +0200
    Patch commit.
 
    Signed-off-by: Peter
This article is based on Ariejan de Vroom's article.

The commands in short

New branch:
git checkout -b my-new-branch

Do changes and commit:
git commit -am "My changes."

Create the patch:
git format-patch master --stdout > fix_empty_poster.patch

Checkout to your master branch (or any other):
git checkout master

Check if patch can be applied:
git apply --check fix_empty_poster.patch 

Check the impact:
git apply --stat fix_empty_poster.patch

Apply and commit the patch:
git am --signoff < fix_empty_poster.patch 

Montag, 21. März 2016

Debugging PHP CLI scripts in PhpStorm which are running inside a Vagrant Box (Xdebug)

Please notice: This article is for debugging with Xdebug. Not any "old-fashioned" debugging with var_dump(); or print_r() or any other "90ies webmastering style".

Remote debugging by SSH tunnel and the PhpStorm debugger only

Additional settings in /etc/php5/cli/php.ini:

xdebug.remote_enable=true
xdebug.remote_autostart=true
xdebug.remote_port=9000
xdebug.remote_connect_back=1

Then connect to the server via SSH tunnel:

ssh -R 9000:localhost:9000 username_goes_here@hostname_goes_here 

Start a script via PHP from the command line and PhpStorm will react (debugging button in PhpStorm must be turned on and the mapping for the directories must be set).

This works, if you have not a weird issue with not available execution point inside PHPStorm's debugging window and there's no solution on the internet.. (Google isn't always your friend)

Remote debugging by the PhpStorm tools

In case that the debugger window will be opened, but the execution point will not be shown, you can run the script from PhpStorm itself.

Firstly you have to set up the remote debugging (Preferences > Languages & Framework > PHP). Choose here a remote interpreter.

If you have not already done so, set it up. The "SSH Credentials" settings have worked for me. While I'm using Vagrant and PhpStorm has an extra Vagrant checkbox (which has not worked for me):

In your PHP command line programs you need to specify often arguments. That can be done also:


sed: Another way of fixing wrong line endings on linux

sed is a stream editor which is pre-installed on linux systems like Ubuntu. It can fix line endings by the following command.

sed -i -e 's/\r$//' scriptname.sh

The manual can be found at http://www.gnu.org/software/sed/manual/sed.html

Mittwoch, 2. März 2016

SSH: Fix folder and file permissions for ~/.ssh folder

SSH is checking the folder and files permissions at ~/.ssh. If there're any problems with reading or writing into that folder, the following command helps out.

chmod 700 ~/.ssh && chmod 600 ~/.ssh/*