예제 #1
0
	def fetch(self, refspec=None, progress=None, **kwargs):
		"""Fetch the latest changes for this remote
		
		:param refspec:
			A "refspec" is used by fetch and push to describe the mapping 
			between remote ref and local ref. They are combined with a colon in 
			the format <src>:<dst>, preceded by an optional plus sign, +. 
			For example: git fetch $URL refs/heads/master:refs/heads/origin means 
			"grab the master branch head from the $URL and store it as my origin 
			branch head". And git push $URL refs/heads/master:refs/heads/to-upstream 
			means "publish my master branch head as to-upstream branch at $URL". 
			See also git-push(1).
			
			Taken from the git manual
		:param progress: See 'push' method
		:param kwargs: Additional arguments to be passed to git-fetch
		:return:
			IterableList(FetchInfo, ...) list of FetchInfo instances providing detailed 
			information about the fetch results
			
		:note:
			As fetch does not provide progress information to non-ttys, we cannot make 
			it available here unfortunately as in the 'push' method."""
		kwargs = add_progress(kwargs, self.repo.git, progress)
		proc = self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
		return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
    def push(self, refspec=None, progress=None, **kwargs):
        """Push changes from source branch in refspec to target branch in refspec.

        :param refspec: see 'fetch' method
        :param progress:
            Instance of type RemoteProgress allowing the caller to receive
            progress information until the method returns.
            If None, progress information will be discarded

        :param kwargs: Additional arguments to be passed to git-push
        :return:
            IterableList(PushInfo, ...) iterable list of PushInfo instances, each
            one informing about an individual head which had been updated on the remote
            side.
            If the push contains rejected heads, these will have the PushInfo.ERROR bit set
            in their flags.
            If the operation fails completely, the length of the returned IterableList will
            be null."""
        kwargs = add_progress(kwargs, self.repo.git, progress)
        proc = self.repo.git.push(self,
                                  refspec,
                                  porcelain=True,
                                  as_process=True,
                                  **kwargs)
        return self._get_push_info(proc, progress or RemoteProgress())
예제 #3
0
	def pull(self, refspec=None, progress=None, **kwargs):
		"""Pull changes from the given branch, being the same as a fetch followed 
		by a merge of branch with your local branch.
		
		:param refspec: see 'fetch' method
		:param progress: see 'push' method
		:param kwargs: Additional arguments to be passed to git-pull
		:return: Please see 'fetch' method """
		kwargs = add_progress(kwargs, self.repo.git, progress)
		proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
		return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
예제 #4
0
def to_progress_instance(progress):
    """Given the 'progress' return a suitable object derived from
    RemoteProgress().
    """
    # new API only needs progress as a function
    if callable(progress):
        return CallableRemoteProgress(progress)

    # where None is passed create a parser that eats the progress
    elif progress is None:
        return RemoteProgress()

    # assume its the old API with an instance of RemoteProgress.
    return progress
예제 #5
0
파일: remote.py 프로젝트: ReaganD/GitPython
    def fetch(self, refspec=None, progress=None, **kwargs):
        """Fetch the latest changes for this remote

        :param refspec:
            A "refspec" is used by fetch and push to describe the mapping
            between remote ref and local ref. They are combined with a colon in
            the format <src>:<dst>, preceded by an optional plus sign, +.
            For example: git fetch $URL refs/heads/master:refs/heads/origin means
            "grab the master branch head from the $URL and store it as my origin
            branch head". And git push $URL refs/heads/master:refs/heads/to-upstream
            means "publish my master branch head as to-upstream branch at $URL".
            See also git-push(1).

            Taken from the git manual

            Fetch supports multiple refspecs (as the
            underlying git-fetch does) - supplying a list rather than a string
            for 'refspec' will make use of this facility.
        :param progress: See 'push' method
        :param kwargs: Additional arguments to be passed to git-fetch
        :return:
            IterableList(FetchInfo, ...) list of FetchInfo instances providing detailed
            information about the fetch results

        :note:
            As fetch does not provide progress information to non-ttys, we cannot make
            it available here unfortunately as in the 'push' method."""
        if refspec is None:
            # No argument refspec, then ensure the repo's config has a fetch refspec.
            self._assert_refspec()
        kwargs = add_progress(kwargs, self.repo.git, progress)
        if isinstance(refspec, list):
            args = refspec
        else:
            args = [refspec]

        proc = self.repo.git.fetch(self,
                                   *args,
                                   as_process=True,
                                   with_stdout=False,
                                   v=True,
                                   **kwargs)
        res = self._get_fetch_info_from_stderr(proc, progress
                                               or RemoteProgress())
        if hasattr(self.repo.odb, 'update_cache'):
            self.repo.odb.update_cache()
        return res
예제 #6
0
    def pull(self, refspec=None, progress=None, **kwargs):
        """Pull changes from the given branch, being the same as a fetch followed
        by a merge of branch with your local branch.

        :param refspec: see 'fetch' method
        :param progress: see 'push' method
        :param kwargs: Additional arguments to be passed to git-pull
        :return: Please see 'fetch' method """
        if refspec is None:
            # No argument refspec, then ensure the repo's config has a fetch refspec.
            self._assert_refspec()
        kwargs = add_progress(kwargs, self.repo.git, progress)
        proc = self.repo.git.pull(self, refspec, with_stdout=False, as_process=True, v=True, **kwargs)
        res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
        if hasattr(self.repo.odb, 'update_cache'):
            self.repo.odb.update_cache()
        return res
예제 #7
0
def run(args, remainder=None):
    osppath = osp.OSP()
    num = [args.add, args.rename, args.remove]
    if num.count(False) + num.count(None) < 2:
        print("usage: " + usage)
        return
    if args.add:
        if len(remainder) < 2:
            print("usage: " + usage)
            return
        else:
            name = remainder[0]
            url = remainder[1]
            dest = None
            if len(remainder) >= 3:
                dest = remainder[2]
                if not (os.path.exists(url) and os.path.isdir(url)):
                    print_string("% is not a valid path" % dest)
                    dest = None
            if os.path.exists(url) and os.path.isdir(url):
                source_type = "local"
                url = os.path.abspath(url)
                msg = "Add this local (%s) to user profile osp.json" % (url)
                print_string(msg)
                osppath.set_path(name, source_type, url)
                args.list = True

            elif os.path.exists(url) and os.path.isfile(url):
                if url.endswith("zip"):
                    dest_dir = dest if dest else getcwd()
                    path = os.path.join(dest_dir, name)
                    result = unzip(url, name)
                    if not result:
                        msg = "Unzip zip failed"
                        print_string(msg, level="error")
                    else:
                        source_type = "zip"
                        osppath.set_path(name, source_type, path, url)
                        print_string("Add (%s) to user profile osp.json" %
                                     path)
                        args.list = True
            elif url == EMBARC_OSP_URL:
                if not os.path.exists(name):
                    path = dest if dest else getcwd()
                    print_string("Start clone {}".format(url))
                    git.Repo.clone_from(url, os.path.join(path, name),
                                        RemoteProgress())
                    source_type = "git"
                    osppath.set_path(name, source_type,
                                     os.path.join(path, name), url)
                    print_string("Add (%s) to user profile osp.json" %
                                 os.path.join(path, name))
                    args.list = True
                else:
                    print_string(
                        "There is already a folder or file named '%s' under current path"
                        % name)
                    return
            else:
                print("usage: " + usage)
                return
    elif args.rename:
        if len(remainder) != 2:
            print("usage: " + usage)
        else:
            old = remainder[0]
            new = remainder[1]
            print_string("Start rename {} to {}".format(old, new))
            osppath.rename(old, new)
            args.list = True
    elif args.remove:
        name = args.remove
        print_string("Start remove {} ".format(name))
        osppath.remove_path(name)
        args.list = True
    elif args.set:
        name = args.set
        print_string("Set %s as global EMBARC_OSP_ROOT" % name)
        if osppath.get_path(name):
            config = "EMBARC_OSP_ROOT"
            osppath.set_global(config, name)
        else:
            print_string("This is not a valid osp path")
            args.list = True
    else:
        if remainder:
            print("usage: " + usage)
            return

    if args.list:
        print_string("Current recored embARC source code")
        current_paths = osppath.list_path()
        makefile = osppath.get_makefile(getcwd())
        app_setting = dict()
        current_osp = None
        if makefile:
            if os.path.exists("embarc_app.json"):
                app_setting = read_json("embarc_app.json")
                current_osp = app_setting.get("EMBARC_OSP_ROOT", False)
            else:
                _, app_setting = osppath.get_makefile_config(app_setting)
                current_osp = app_setting.get("EMBARC_OSP_ROOT", False)
        if current_paths:
            osppath.list_path(show=True, current=current_osp)