Example #1
0
File: git.py Project: numerodix/re
 def cmd_set_tracking(self, track_branch):
     remote_pointer = StrFmt.fmt_branch_remote_pointer(track_branch.name)
     merge_pointer = StrFmt.fmt_branch_merge_pointer(track_branch.name)
     rem_name = Git.set_conf_key(self.repo.path, remote_pointer,
                                 track_branch.remote.name)
     longname = Git.set_conf_key(self.repo.path, merge_pointer,
                                 StrFmt.fmt_branch_longname(track_branch.name))
Example #2
0
 def cmd_set_tracking(self, track_branch):
     remote_pointer = StrFmt.fmt_branch_remote_pointer(track_branch.name)
     merge_pointer = StrFmt.fmt_branch_merge_pointer(track_branch.name)
     rem_name = Git.set_conf_key(self.repo.path, remote_pointer,
                                 track_branch.remote.name)
     longname = Git.set_conf_key(
         self.repo.path, merge_pointer,
         StrFmt.fmt_branch_longname(track_branch.name))
Example #3
0
File: git.py Project: numerodix/re
 def detect_branches(cls, repo):
     for longname in Git.get_branches_remote_tracking(repo.path):
         if 'HEAD' in longname:  # special case
             continue
         remote, name = StrFmt.split_branch_longname(longname, parts=2)
         remote = Remote.get_remote(repo, remote)
         branch = BranchRemoteTracking.get_branch(repo, remote, longname, name)
Example #4
0
 def detect_branches(cls, repo):
     for longname in Git.get_branches_remote_tracking(repo.path):
         if 'HEAD' in longname:  # special case
             continue
         remote, name = StrFmt.split_branch_longname(longname, parts=2)
         remote = Remote.get_remote(repo, remote)
         branch = BranchRemoteTracking.get_branch(repo, remote, longname,
                                                  name)
Example #5
0
File: git.py Project: numerodix/re
    def detect_tracking(self):
        remote_pointer = StrFmt.fmt_branch_remote_pointer(self.name)
        merge_pointer = StrFmt.fmt_branch_merge_pointer(self.name)
        rem_name = Git.get_conf_key(self.repo.path, remote_pointer)
        longname = Git.get_conf_key(self.repo.path, merge_pointer)

        if rem_name and longname:
            _, _, br_name = StrFmt.split_branch_longname(longname, parts=3)

            remote = Remote.get_remote(self.repo, rem_name)
            branch = BranchRemoteTracking.get_branch(self.repo, remote, longname,
                                                     br_name)

            branch.tracked_by = self
            self.tracking = branch

            logger.info('Detected local tracking branch %s on %s/%s' %
                        (self.name, rem_name, br_name))
Example #6
0
    def detect_tracking(self):
        remote_pointer = StrFmt.fmt_branch_remote_pointer(self.name)
        merge_pointer = StrFmt.fmt_branch_merge_pointer(self.name)
        rem_name = Git.get_conf_key(self.repo.path, remote_pointer)
        longname = Git.get_conf_key(self.repo.path, merge_pointer)

        if rem_name and longname:
            _, _, br_name = StrFmt.split_branch_longname(longname, parts=3)

            remote = Remote.get_remote(self.repo, rem_name)
            branch = BranchRemoteTracking.get_branch(self.repo, remote,
                                                     longname, br_name)

            branch.tracked_by = self
            self.tracking = branch

            logger.info('Detected local tracking branch %s on %s/%s' %
                        (self.name, rem_name, br_name))
Example #7
0
File: git.py Project: numerodix/re
 def cmd_merge(self, branch):
     longname = StrFmt.fmt_branch_remote_tracking(branch.remote.name, branch.name)
     if Git.commit_is_ahead_of(self.repo.path, self.name, longname):
         ioutils.suggest('Branch %s is ahead of %s, is pushable' %
                         (self.name, longname), minor=True)
         return True
     else:
         if self.cmd_checkout():
             remoted = StrFmt.fmt_branch_remote_tracking(branch.remote.name,
                                                         branch.name)
             merge_ok, output = Git.merge(self.repo.path, remoted)
             if merge_ok:
                 if output:
                     ioutils.inform('Merged %s on %s' % (longname, self.name),
                                    minor=True)
                     ioutils.output(output)
                 return True
             else:
                 Git.reset_hard(self.repo.path, self.name)
Example #8
0
 def cmd_merge(self, branch):
     longname = StrFmt.fmt_branch_remote_tracking(branch.remote.name,
                                                  branch.name)
     if Git.commit_is_ahead_of(self.repo.path, self.name, longname):
         ioutils.suggest('Branch %s is ahead of %s, is pushable' %
                         (self.name, longname),
                         minor=True)
         return True
     else:
         if self.cmd_checkout():
             remoted = StrFmt.fmt_branch_remote_tracking(
                 branch.remote.name, branch.name)
             merge_ok, output = Git.merge(self.repo.path, remoted)
             if merge_ok:
                 if output:
                     ioutils.inform('Merged %s on %s' %
                                    (longname, self.name),
                                    minor=True)
                     ioutils.output(output)
                 return True
             else:
                 Git.reset_hard(self.repo.path, self.name)
Example #9
0
File: git.py Project: numerodix/re
    def from_cfg_attributes(cls, path, attributes):
        repo = GitRepo(path)
        for key, val in attributes.items():
            name, key = StrFmt.split_cfg_key(key)

            remote = Remote(repo, name)
            if not repo.remotes:  # this is the first remote
                remote.is_canonical = True
            if not remote.name in repo.remotes:
                repo.remotes[remote.name] = remote

            remote = repo.remotes[remote.name]
            remote.urls[key] = val
        return repo
Example #10
0
    def from_cfg_attributes(cls, path, attributes):
        repo = GitRepo(path)
        for key, val in attributes.items():
            name, key = StrFmt.split_cfg_key(key)

            remote = Remote(repo, name)
            if not repo.remotes:  # this is the first remote
                remote.is_canonical = True
            if not remote.name in repo.remotes:
                repo.remotes[remote.name] = remote

            remote = repo.remotes[remote.name]
            remote.urls[key] = val
        return repo
Example #11
0
File: git.py Project: numerodix/re
    def from_checkout(cls, path):
        repo = GitRepo(path)

        names = Git.get_remotes(path)
        for name in names:
            remote = Remote(repo, name)
            repo.remotes[name] = remote

            for url in ['url', 'pushurl']:
                key = StrFmt.fmt_remote_key(name, url)
                val = Git.get_conf_key(path, key)
                if val:
                    remote.urls[url] = val

        return repo
Example #12
0
    def from_checkout(cls, path):
        repo = GitRepo(path)

        names = Git.get_remotes(path)
        for name in names:
            remote = Remote(repo, name)
            repo.remotes[name] = remote

            for url in ['url', 'pushurl']:
                key = StrFmt.fmt_remote_key(name, url)
                val = Git.get_conf_key(path, key)
                if val:
                    remote.urls[url] = val

        return repo
Example #13
0
File: git.py Project: numerodix/re
    def set_remotes_in_checkout(self):
        logger.info('Setting remotes in checkout')

        # remove remotes not in model
        remotes_names = Git.get_remotes(self.path)
        names = filter(lambda n: n not in self.remotes, remotes_names)
        for name in names:
            Git.remove_remote(self.path, name)

        # add remotes not in checkout
        names = filter(lambda n: n not in remotes_names, self.remotes.keys())
        for name in names:
            Git.add_remote(self.path, name, self.remotes[name].urls['url'])

        # overwrite urls in checkout
        for remote in self.remotes.values():
            for key, val in remote.urls.items():
                key = StrFmt.fmt_remote_key(remote.name, key)
                Git.set_conf_key(self.path, key, val)
Example #14
0
    def set_remotes_in_checkout(self):
        logger.info('Setting remotes in checkout')

        # remove remotes not in model
        remotes_names = Git.get_remotes(self.path)
        names = filter(lambda n: n not in self.remotes, remotes_names)
        for name in names:
            Git.remove_remote(self.path, name)

        # add remotes not in checkout
        names = filter(lambda n: n not in remotes_names, self.remotes.keys())
        for name in names:
            Git.add_remote(self.path, name, self.remotes[name].urls['url'])

        # overwrite urls in checkout
        for remote in self.remotes.values():
            for key, val in remote.urls.items():
                key = StrFmt.fmt_remote_key(remote.name, key)
                Git.set_conf_key(self.path, key, val)
Example #15
0
File: git.py Project: numerodix/re
    def attributes_to_cfg(self):
        names = self.remotes.keys()
        names.sort()

        # find canonical remote
        remotes = filter(lambda r: r.is_canonical, self.remotes.values())
        if remotes:
            name = remotes[0].name
            names = utils.sort_with_elem_as_first(name, names)

        for key in names:
            remote = self.remotes[key]

            urls = remote.urls.keys()
            urls = utils.sort_with_elem_as_first('url', urls)

            for att in urls:
                val = remote.urls[att]
                att = StrFmt.fmt_cfg_key(remote.name, att)
                yield att, val
Example #16
0
    def attributes_to_cfg(self):
        names = self.remotes.keys()
        names.sort()

        # find canonical remote
        remotes = filter(lambda r: r.is_canonical, self.remotes.values())
        if remotes:
            name = remotes[0].name
            names = utils.sort_with_elem_as_first(name, names)

        for key in names:
            remote = self.remotes[key]

            urls = remote.urls.keys()
            urls = utils.sort_with_elem_as_first('url', urls)

            for att in urls:
                val = remote.urls[att]
                att = StrFmt.fmt_cfg_key(remote.name, att)
                yield att, val