From 129f90aa8d83d9b250c87b0ba790605c4a2bb06a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 24 Jun 2010 01:07:58 +0200 Subject: Multiple partly critical bugfixes related to index handling --- lib/git/index/util.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/git/index/util.py') diff --git a/lib/git/index/util.py b/lib/git/index/util.py index c9fb1922..bd5fcc03 100644 --- a/lib/git/index/util.py +++ b/lib/git/index/util.py @@ -3,7 +3,7 @@ import struct import tempfile import os -__all__ = ( 'TemporaryFileSwap', 'post_clear_cache', 'default_index' ) +__all__ = ( 'TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir' ) #{ Aliases pack = struct.pack @@ -67,4 +67,20 @@ def default_index(func): check_default_index.__name__ = func.__name__ return check_default_index +def git_working_dir(func): + """Decorator which changes the current working dir to the one of the git + repository in order to assure relative paths are handled correctly""" + def set_git_working_dir(self, *args, **kwargs): + cur_wd = os.getcwd() + os.chdir(self.repo.working_tree_dir) + try: + return func(self, *args, **kwargs) + finally: + os.chdir(cur_wd) + # END handle working dir + # END wrapper + + set_git_working_dir.__name__ = func.__name__ + return set_git_working_dir + #} END decorators -- cgit v1.2.1