◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
4 changes: 4 additions & 0 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from unittest.case import SkipTest
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
from git.objects.base import IndexObject, Object

__all__ = ["Submodule", "UpdateProgress"]

Expand Down Expand Up @@ -394,6 +395,9 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
mrepo = cls._clone_repo(repo, url, path, name, **kwargs)
# END verify url

# It's important to add the URL to the parent config, to let `git submodule` know.
# otherwise there is a '-' character in front of the submodule listing
# a38efa84daef914e4de58d1905a500d8d14aaf45 mymodule (v0.9.0-1-ga38efa8)
Expand Down
44 changes: 20 additions & 24 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
)
from git.util import (
join_path,
finalize_process
)
from git.cmd import handle_process_output
from gitdb.util import join
from git.compat import (defenc, force_text, is_win)
import logging
Expand Up @@ -570,7 +569,7 @@ def create(cls, repo, name, url, **kwargs):
:raise GitCommandError: in case an origin with that name already exists"""
scmd = 'add'
kwargs['insert_kwargs_after'] = scmd
repo.git.remote(scmd, name, url, **kwargs)
return cls(repo, name)

# add is an alias
Expand Down Expand Up @@ -630,25 +629,19 @@ def _get_fetch_info_from_stderr(self, proc, progress):
cmds = set(PushInfo._flag_map.keys()) & set(FetchInfo._flag_map.keys())

progress_handler = progress.new_message_handler()

stderr_text = None

for line in proc.stderr:
line = force_text(line)
for pline in progress_handler(line):
# END handle special messages
for cmd in cmds:
if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
fetch_info_lines.append(line)
continue
# end find command code
# end for each comand code we know
# end for each line progress didn't handle
# end
if progress.error_lines():
stderr_text = '\n'.join(progress.error_lines())

finalize_process(proc, stderr=stderr_text)

# read head information
with open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb') as fp:
Expand Up @@ -687,16 +680,19 @@ def stdout_handler(line):
try:
output.append(PushInfo._from_line(self, line))
except ValueError:
# if an error happens, additional info is given which we cannot parse
pass
# END exception handling
# END for each line

try:
handle_process_output(proc, stdout_handler, progress_handler, finalize_process, decode_streams=False)
except Exception:
if len(output) == 0:
raise
return output

def _assert_refspec(self):
Expand Down
54 changes: 13 additions & 41 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@
import os
import sys
import re
from collections import namedtuple

DefaultDBType = GitCmdObjectDB
if sys.version_info[:2] < (2, 5): # python 2.4 compatiblity
DefaultDBType = GitCmdObjectDB
Expand Up @@ -871,46 +874,15 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
if progress is not None:
progress = to_progress_instance(progress)

# special handling for windows for path at which the clone should be
# created.
# tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence
# we at least give a proper error instead of letting git fail
prev_cwd = None
prev_path = None
odbt = kwargs.pop('odbt', odb_default_type)
if is_win:
if '~' in path:
raise OSError("Git cannot handle the ~ character in path %r correctly" % path)

# on windows, git will think paths like c: are relative and prepend the
# current working dir ( before it fails ). We temporarily adjust the working
# dir to make this actually work
match = re.match("(\w:[/\\\])(.*)", path)
if match:
prev_cwd = os.getcwd()
prev_path = path
drive, rest_of_path = match.groups()
os.chdir(drive)
path = rest_of_path
kwargs['with_keep_cwd'] = True
# END cwd preparation
# END windows handling

try:
proc = git.clone(url, path, with_extended_output=True, as_process=True,
v=True, **add_progress(kwargs, git, progress))
if progress:
handle_process_output(proc, None, progress.new_message_handler(), finalize_process)
else:
(stdout, stderr) = proc.communicate() # FIXME: Will block of outputs are big!
finalize_process(proc, stderr=stderr)
# end handle progress
finally:
if prev_cwd is not None:
os.chdir(prev_cwd)
path = prev_path
# END reset previous working dir
# END bad windows handling

# our git command could have a different working dir than our actual
# environment, hence we prepend its working dir if required
Expand All @@ -922,10 +894,10 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
# that contains the remote from which we were clones, git stops liking it
# as it will escape the backslashes. Hence we undo the escaping just to be
# sure
repo = cls(os.path.abspath(path), odbt=odbt)
if repo.remotes:
with repo.remotes[0].config_writer as writer:
writer.set_value('url', repo.remotes[0].url.replace("\\\\", "\\").replace("\\", "/"))
# END handle remote repo
return repo

Expand Down
Loading
Toggle all file notes Toggle all file annotations