Yearly Archives: 2017


Forcing user to remove trailing spaces in git

There are simple ways to force the user in removing trailing spaces before committing code in git using hooks.
Below we will present a solution that is applied at the local computer before the commit stage, which each developer needs to perform in each repository clone they own.
Note: If you would like to have the hooks on the server, you will need extra access rights to modify the hooks on the remote machine, maybe you will even need your systems administrator to configure it.

Solution

Attached you will find a file named pre-commit ([download id=”3933″]) it is a hook that get applied before the user is allowed to even commit.
That file you need to copy it (after you extract it) in the .git/hooks folder of your cloned repositories and you are done!

What this script does is simple, if there are whitespace errors, it prints the offending file names and fails.
What are considered whitespace errors is controlled by core.whitespace configuration.
By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.

In case you need to commit files that have whitespace errors, you can bypass the checks that are applied by the hooks using the --no-verify flag as follows:

git commit -m "Some informative message" --no-verify;

There are more ways to achieve this result, others are more verbose but this one is the simplest and more flexible as you can configure it using the git configuration variables.

[download id=”3933″]

#!/bin/sh
#
# This hook script verifies that there are no whitespace errors in the files to be committed

if git rev-parse --verify HEAD >/dev/null 2>&1
then
 against=HEAD
else
 # Initial commit: diff against an empty tree object
 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Redirect output to stderr.
exec 1>&2

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --

[download id=”3933″]


IEEETran Latex Template – Add Copyrights on left bottom of first page of Conference class 2

Using the conference class in the IEEETran Latex template, it blocks you from using the IEEEpubid command that can be used to add the copyright note on the bottom of the screen.

Attempt 1 – Enable overrides only

We added the IEEEoverridecommandlockouts command right after the documentclass directive, that allows us to use functionality in IEEETran that should be blocked depending on the document class.
Then we used the IEEEpubid command right after the documentclass directive to create and print the copyright note:

\IEEEpubid{978-1-5386-2880-5/17/\$31.00~\copyright~2017 IEEE}

Doing so, resulted in printing the copyright note in the bottom middle of the first page. The conference class is a two column style, the left column got pushed up a bit to make space, while the right did not. In the end, half of the copyright note was overlapping with the second column.

Attempt 2 – Solution – Customize IEEEpubid as well

After documentclass we added the IEEEoverridecommandlockouts command to enable functionality that is blocked for the conference class.
Then we created our own IEEEpudid command that places itself in a column and not a page as follows:

\documentclass[conference]{IEEEtran}
%Enabled blocked functionality
\IEEEoverridecommandlockouts
%Define custom IEEEpubid that will place it self in a column and not a page, suitable from conference class
\IEEEpubid{\makebox[\columnwidth]{978-1-5386-2880-5/17/\$31.00~\copyright~2017 IEEE \hfill} \hspace{\columnsep}\makebox[\columnwidth]{ }}

Finally after the maketitle command we added IEEEpubidadjcol to give more space between the copyright note and the body of first column.

\maketitle
%Add space between copyright and text
\IEEEpubidadjcol