Ejemplo n.º 1
0
    def create(self) -> None:
        if GitOffline.has_tracking_branch(self.path, self.local_branch.name):
            CONSOLE.stdout(' - Tracking branch already exists')
            return
        # TODO: Add Format util to format tracking branch output: local_branch -> remote remote_branch
        CONSOLE.stdout(
            f' - Create tracking branch {Format.Git.ref(self.name)}')
        GitOnline.fetch(self.path, prune=True)
        # local and remote branches exist
        if self.local_branch.exists and self.upstream_branch.exists:
            self.set_upstream()
            return

        # only local branch exists
        if self.local_branch.exists:
            # GitOnline.push(self.path,
            #                local_branch=self.name,
            #                remote_branch=self.upstream_branch.name,
            #                remote=self.upstream_branch.remote.name,
            #                set_upstream=True)
            self.upstream_branch.create(branch=self.local_branch.name)
            self.set_upstream()
            GitOnline.fetch(self.path, prune=True)
            return

        # only remote branch exists
        if self.upstream_branch.exists:
            self.local_branch.create(branch=self.upstream_branch.name,
                                     remote=self.upstream_branch.remote.name)
            # GitOffline.create_local_branch(self.path, self.name,
            #                                branch=self.upstream_branch.name,
            #                                remote=self.upstream_branch.remote)
            return

        # local and remote branches DO NOT exist
        self.upstream_branch.create()
        GitOnline.fetch(self.path, prune=True)
        self.local_branch.create(branch=self.upstream_branch.name,
                                 remote=self.upstream_branch.remote.name)
Ejemplo n.º 2
0
 def is_tracking_branch(self) -> bool:
     return GitOffline.has_tracking_branch(self.path, self.name)