diff --git a/src/run_unitary_tests_in_directory.m b/src/run_unitary_tests_in_directory.m
index 5485e6b22fb64cfa8ee8d8c51ff8fc770f3aa048..93ef397d688707abfdc46305f62425df8c98d6fd 100644
--- a/src/run_unitary_tests_in_directory.m
+++ b/src/run_unitary_tests_in_directory.m
@@ -33,6 +33,10 @@ function report = run_unitary_tests_in_directory(dirname, savereport, printrepor
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+INIT_PATH = pwd();
+
+cd(dirname);
+
 system('git show --pretty=format:"Last commit %H by %an, %ar %n-> %s" HEAD > git.info');
 system('git rev-parse HEAD > git.last-commit-hash');
 
@@ -45,6 +49,8 @@ fid = fopen('git.last-commit-hash');
 gitlastcommithash = fgetl(fid);
 fclose(fid);
 
+cd(INIT_PATH);
+
 matlabverion = version;
 platform = computer;
 
@@ -60,4 +66,4 @@ end
 
 if nargin>2
     build_report_summary(['report-' gitlastcommithash '.mat'], printreport, sendreport);
-end
\ No newline at end of file
+end