Beispiel #1
0
    def subclients(self, parent_commit):
        """Return mapping from submodule to client."""
        if parent_commit in self._subclients:
            return self._subclients[parent_commit]

        try:
            from git import Submodule

            submodules = [
                submodule for submodule in Submodule.iter_items(
                    self.repo, parent_commit=parent_commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules associated with the given commit.
            submodules = []

        subclients = {}
        for submodule in submodules:
            subpath = (self.path / submodule.path).resolve()
            is_renku = subpath / Path(self.renku_home)

            if subpath.exists() and is_renku.exists():
                subclients[submodule] = self.__class__(
                    path=subpath,
                    parent=(self, submodule),
                )

        return subclients
Beispiel #2
0
	def _exec_add(self, options, args):
		"""Add a new submodule. The last arg may be the url, which is optional"""
		if len(args) < 2 or len(args) > 3:
			raise self.parser.error("arguments may be: name path [url]")
		# END handle arg count
		
		sm = Submodule.add(self.repo, *args, branch=options.branch, no_checkout=options.no_checkout)
		print "Created submodule %r at path %s" % (sm.name, sm.path)
Beispiel #3
0
    def add_file(self, path, revision='HEAD'):
        """Add a file node to the graph."""
        file_commits = list(self.client.git.iter_commits(revision, paths=path))

        if not file_commits:
            raise KeyError('Could not find a file {0} in range {1}'.format(
                path, revision))

        commit = file_commits[0]

        cwl = self.find_cwl(commit)
        if cwl is not None:
            file_key = self.add_node(commit, path)
            self.add_tool(commit, cwl, file_key=file_key)
            return file_key
        else:
            #: Does not have a parent CWL.
            root_node = self.add_node(commit, path)
            parent_commit, parent_path = root_node

            #: Capture information about the submodule in a submodule.
            root_submodule = self.G.nodes[root_node].get('submodule', [])

            #: Resolve Renku based submodules.
            original_path = Path(parent_path)
            if original_path.is_symlink() or str(original_path).startswith(
                    '.renku/vendors'):
                original_path = original_path.resolve()

                for submodule in Submodule.iter_items(
                        self.client.git, parent_commit=parent_commit):
                    try:
                        subpath = original_path.relative_to(
                            Path(submodule.path).resolve())
                        subgraph = Graph(client=LocalClient(
                            path=submodule.path))
                        subnode = subgraph.add_file(str(subpath),
                                                    revision=submodule.hexsha)

                        #: Extend node metadata.
                        for _, data in subgraph.G.nodes(data=True):
                            data['submodule'] = root_submodule + [
                                submodule.name
                            ]

                        #: Merge file node with it's symlinked version.
                        self.G = nx.contracted_nodes(
                            nx.compose(self.G, subgraph.G),
                            root_node,
                            subnode,
                        )  # TODO optionally it can be changed to an edge.
                        break
                    except ValueError:
                        continue

            return root_node
Beispiel #4
0
    def _exec_add(self, options, args):
        """Add a new submodule. The last arg may be the url, which is optional"""
        if len(args) < 2 or len(args) > 3:
            raise self.parser.error("arguments may be: name path [url]")
        # END handle arg count

        sm = Submodule.add(self.repo,
                           *args,
                           branch=options.branch,
                           no_checkout=options.no_checkout)
        print "Created submodule %r at path %s" % (sm.name, sm.path)
Beispiel #5
0
    def test_diff_submodule(self):
        """Test that diff is able to correctly diff commits that cover submodule changes"""
        # Init a temp git repo that will be referenced as a submodule
        sub = Repo.init(self.submodule_dir)
        with open(self.submodule_dir + "/subfile", "w") as sub_subfile:
            sub_subfile.write("")
        sub.index.add(["subfile"])
        sub.index.commit("first commit")

        # Init a temp git repo that will incorporate the submodule
        repo = Repo.init(self.repo_dir)
        with open(self.repo_dir + "/test", "w") as foo_test:
            foo_test.write("")
        repo.index.add(['test'])
        Submodule.add(repo,
                      "subtest",
                      "sub",
                      url="file://" + self.submodule_dir)
        repo.index.commit("first commit")
        repo.create_tag('1')

        # Add a commit to the submodule
        submodule = repo.submodule('subtest')
        with open(self.repo_dir + "/sub/subfile", "w") as foo_sub_subfile:
            foo_sub_subfile.write("blub")
        submodule.module().index.add(["subfile"])
        submodule.module().index.commit("changed subfile")
        submodule.binsha = submodule.module().head.commit.binsha

        # Commit submodule updates in parent repo
        repo.index.add([submodule])
        repo.index.commit("submodule changed")
        repo.create_tag('2')

        diff = repo.commit('1').diff(repo.commit('2'))[0]
        # If diff is unable to find the commit hashes (looks in wrong repo) the *_blob.size
        # property will be a string containing exception text, an int indicates success
        self.assertIsInstance(diff.a_blob.size, int)
        self.assertIsInstance(diff.b_blob.size, int)
Beispiel #6
0
    def subclients(self, parent_commit):
        """Return mapping from submodule to client."""
        if parent_commit in self._subclients:
            return self._subclients[parent_commit]

        try:
            from git import Submodule

            submodules = [
                submodule for submodule in Submodule.iter_items(
                    self.repo, parent_commit=parent_commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules assiciated with the given commit.
            submodules = []

        return self._subclients.setdefault(
            parent_commit, {
                submodule: self.__class__(
                    path=(self.path / submodule.path).resolve(),
                    parent=(self, submodule),
                )
                for submodule in submodules
            })
Beispiel #7
0
def Update(repo: git.Repo, submodule: git.Submodule, recursive=False):
    """Runs an update appropriate for updating the checkout to the
    latest available revision.
    """
    submodule.update(recursive, True, True)
Beispiel #8
0
def Checkout(repo: git.Repo, submodule: git.Submodule, recursive=False):
    """Runs an update appropriate for an initial checkout of this submodule.
    """
    submodule.update(recursive, True)
    repo = Repo(repo_dir)
except InvalidGitRepositoryError as e:
    repo = False

if repo is False:
    # Init repository
    repo = Repo.init(repo_dir)
    repo.git.branch("-m", ODOO_VERSION)

    # Add submodules
    for submodule in REPOS:
        print(f"Adding submodule {submodule['name']}.")
        Submodule.add(
            repo,
            submodule["name"],
            os.path.join(repo_dir, f"submodules/{submodule['name']}"),
            submodule["url"],
            ODOO_VERSION,
            depth=1,
        )
    for submodule in REPOS_MASTER:
        print(f"Adding submodule {submodule['name']}.")
        Submodule.add(
            repo,
            submodule["name"],
            os.path.join(repo_dir, f"submodules/{submodule['name']}"),
            submodule["url"],
            "master",
            depth=1,
        )
    try:
        repo.git.commit("-m", "[ADD] Submodules.")
Beispiel #10
0
    def default_inputs(self):
        """Guess default inputs from a process."""
        basedir = os.path.dirname(self.path)
        commit = self.commit
        client = self.client
        process = self.process
        hierarchy = self.submodules

        inputs = {}
        revision = '{0}^'.format(commit)

        try:
            from git import Submodule

            submodules = [
                submodule
                for submodule in Submodule.iter_items(client.git,
                                                      parent_commit=commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules assiciated with the given commit.
            submodules = []

        subclients = {
            submodule: LocalClient(
                path=(client.path / submodule.path).resolve(),
                parent=client,
            )
            for submodule in submodules
        }

        def resolve_submodules(file_, **kwargs):
            original_path = client.path / file_
            if original_path.is_symlink() or file_.startswith(
                    '.renku/vendors'):
                original_path = original_path.resolve()
                for submodule, subclient in subclients.items():
                    try:
                        subpath = original_path.relative_to(subclient.path)
                        return Usage.from_revision(client=subclient,
                                                   path=str(subpath),
                                                   revision=submodule.hexsha,
                                                   submodules=hierarchy +
                                                   [submodule.name],
                                                   **kwargs)
                    except ValueError:
                        pass

        for input_id, input_path in process.iter_input_files(basedir):
            try:
                usage_id = self._id + '/inputs/' + input_id
                dependency = resolve_submodules(
                    input_path,
                    role=input_id,
                    id=usage_id,
                )
                if dependency is None:
                    dependency = Usage.from_revision(
                        client=client,
                        path=input_path,
                        role=input_id,
                        revision=revision,
                        id=usage_id,
                    )
                inputs[input_path] = dependency
            except KeyError:
                continue

        return inputs
Beispiel #11
0
 def _exec_add(self, args):
     """Add a new submodule. The last arg may be the url, which is optional"""
     sm = Submodule.add(self.repo, args.name, args.path, args.url, branch=args.branch, no_checkout=args.no_checkout)
     self.log().info("Created submodule %r at path %s", sm.name, sm.path)
Beispiel #12
0
""" el = repo.heads.master.log()
print(el[0])
print(el[-1]) """
""" print(repo.head.commit.tree.blobs[1].data_stream.read())

print(repo.commit('HEAD'))
commits = list(repo.iter_commits('master'))
print(commits) """
""" for commit in commits:
  print(commit.committed_date)
  print(commit.message) """
#print(repo.active_branch)
""" print(repo.heads)
repo.heads['master'].checkout()
print(repo.head.reference) """
""" print(repo.submodule)
#For creating a submodule
Submodule.add(repo, 'test', './fullstack-interview-test/sm', url='https://github.com/Danble/fullstack-interview-test') """
#print(repo.submodules)

alfonso = repo.branches['alfonsolzrg-add-instructions'].checkout()
generator = repo.iter_commits()
print(next(generator))
print(next(generator))

master = repo.branches['master'].checkout()
generator = repo.iter_commits()
print(next(generator))
print(next(generator))
print(next(generator))
#print(next(generator))