@@ -121,9 +121,9 @@ def _set_cache_(self, attr):
121121# default submodule values
122122try :
123123self .path = reader .get ('path' )
124- except cp .NoSectionError :
124+ except cp .NoSectionError as e :
125125raise ValueError ("This submodule instance does not exist anymore in '%s' file"
126- % osp .join (self .repo .working_tree_dir ,'.gitmodules' ))
126+ % osp .join (self .repo .working_tree_dir ,'.gitmodules' ))from e
127127# end
128128self ._url = reader .get ('url' )
129129# git-python extension values - optional
@@ -189,9 +189,9 @@ def _config_parser(cls, repo, parent_commit, read_only):
189189assert parent_commit is not None ,"need valid parent_commit in bare repositories"
190190try :
191191fp_module = cls ._sio_modules (parent_commit )
192- except KeyError :
192+ except KeyError as e :
193193raise IOError ("Could not find %s file in the tree of parent commit %s" %
194- (cls .k_modules_file ,parent_commit ))
194+ (cls .k_modules_file ,parent_commit ))from e
195195# END handle exceptions
196196# END handle non-bare working tree
197197
@@ -516,9 +516,9 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
516516if not dry_run and osp .isdir (checkout_module_abspath ):
517517try :
518518os .rmdir (checkout_module_abspath )
519- except OSError :
519+ except OSError as e :
520520raise OSError ("Module directory at %r does already exist and is non-empty"
521- % checkout_module_abspath )
521+ % checkout_module_abspath )from e
522522# END handle OSError
523523# END handle directory removal
524524
@@ -737,8 +737,8 @@ def move(self, module_path, configuration=True, module=True):
737737del (index .entries [ekey ])
738738nentry = git .IndexEntry (entry [:3 ]+ (module_checkout_path ,)+ entry [4 :])
739739index .entries [tekey ]= nentry
740- except KeyError :
741- raise InvalidGitRepositoryError ("Submodule's entry at %r did not exist" % (self .path ))
740+ except KeyError as e :
741+ raise InvalidGitRepositoryError ("Submodule's entry at %r did not exist" % (self .path ))from e
742742# END handle submodule doesn't exist
743743
744744# update configuration
@@ -871,7 +871,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
871871rmtree (wtd )
872872except Exception as ex :
873873if HIDE_WINDOWS_KNOWN_ERRORS :
874- raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex ))
874+ raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex ))from ex
875875raise
876876# END delete tree if possible
877877# END handle force
@@ -882,7 +882,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
882882rmtree (git_dir )
883883except Exception as ex :
884884if HIDE_WINDOWS_KNOWN_ERRORS :
885- raise SkipTest ("FIXME: fails with: PermissionError\n %s" ,ex )
885+ raise SkipTest ("FIXME: fails with: PermissionError\n %s" ,ex )from ex
886886else :
887887raise
888888# end handle separate bare repository
@@ -1046,8 +1046,8 @@ def module(self):
10461046if repo != self .repo :
10471047return repo
10481048# END handle repo uninitialized
1049- except (InvalidGitRepositoryError ,NoSuchPathError ):
1050- raise InvalidGitRepositoryError ("No valid repository at %s" % module_checkout_abspath )
1049+ except (InvalidGitRepositoryError ,NoSuchPathError )as e :
1050+ raise InvalidGitRepositoryError ("No valid repository at %s" % module_checkout_abspath )from e
10511051else :
10521052raise InvalidGitRepositoryError ("Repository at %r was not yet checked out" % module_checkout_abspath )
10531053# END handle exceptions