예제 #1
0
파일: git.py 프로젝트: crazyscot/muddle
 def _git_describe_long(self,
                        co_leaf,
                        orig_revision,
                        force=False,
                        verbose=True):
     """
     This returns a "pretty" name for the revision, but only if there
     are annotated tags in its history.
     """
     retcode, revision = utils.run2('git describe --long',
                                    show_command=False)
     if retcode:
         if revision:
             text = utils.indent(revision.strip(), '    ')
             if force:
                 if verbose:
                     print "'git describe --long' had problems with checkout" \
                           " '%s'"%co_leaf
                     print "    %s" % text
                     print "using original revision %s" % orig_revision
                 return orig_revision
         else:
             text = '    (it failed with return code %d)' % retcode
         raise GiveUp("%s\n%s" % (utils.wrap(
             "%s: 'git describe --long'"
             " could not determine a revision id for checkout:" % co_leaf),
                                  text))
     return revision.strip()
예제 #2
0
    def pull(self, repo, options, upstream=None, verbose=True):
        """
        Will be called in the actual checkout's directory.

        This runs Subversion's "update", but only if no merging will be
        needed. That is, first it runs "svn status", and if any lines
        contain a "C" (for Conflict) in columns 0, 1 or 6, then it will not
        perform the update.

          ("svn help status" would call those columns 1, 2 and 7)
        """
        if repo.branch:
            raise utils.GiveUp("Subversion does not support branch"
                               " in 'pull' (branch='%s')"%repo.branch)
        text = utils.get_cmd_data("svn status")
        for line in text:
            if 'C' in (line[0], line[1], line[6]):
                raise utils.GiveUp("%s: 'svn status' says there is a Conflict,"
                                    " refusing to pull:\n%s\nUse 'muddle merge'"
                                    " if you want to merge"%(utils.indent(text,'    ')))

        starting_revno = self._just_revno()

        utils.shell(["svn", "update"] + self._r_option(repo.revision), show_command=verbose)

        # We could try parsing the output of 'svn update' instead, but this is
        # simpler to do...
        ending_revno = self._just_revno()
        # Did we update anything?
        return starting_revno != ending_revno
예제 #3
0
파일: git.py 프로젝트: crazyscot/muddle
    def _calculate_revision(self,
                            co_leaf,
                            orig_revision,
                            force=False,
                            before=None,
                            verbose=True):
        """
        This returns a bare SHA1 object name for the current HEAD

        NB: if 'before' is specified, 'force' is ignored.
        """
        if before:
            print "git rev-list -n 1 --before='%s' HEAD" % before
            retcode, revision = utils.run2(
                "git rev-list -n 1 --before='%s' HEAD" % before,
                show_command=False)
            print retcode, revision
            if retcode:
                if revision:
                    text = utils.indent(revision.strip(), '    ')
                else:
                    text = '    (it failed with return code %d)' % retcode
                raise GiveUp("%s\n%s" % (utils.wrap(
                    "%s:"
                    " \"git rev-list -n 1 --before='%s' HEAD\"'"
                    " could not determine a revision id for checkout:" %
                    (co_leaf, before)), text))
        else:
            retcode, revision = utils.run2('git rev-parse HEAD',
                                           show_command=False)
            if retcode:
                if revision:
                    text = utils.indent(revision.strip(), '    ')
                    if force:
                        if verbose:
                            print "'git rev-parse HEAD' had problems with checkout" \
                                  " '%s'"%co_leaf
                            print "    %s" % text
                            print "using original revision %s" % orig_revision
                        return orig_revision
                else:
                    text = '    (it failed with return code %d)' % retcode
                raise GiveUp("%s\n%s" % (utils.wrap(
                    "%s: 'git rev-parse HEAD'"
                    " could not determine a revision id for checkout:" %
                    co_leaf), text))
        return revision.strip()
예제 #4
0
파일: git.py 프로젝트: Flameeyes/muddle
    def _calculate_revision(self, co_leaf, orig_revision, force=False,
                            before=None, verbose=True):
        """
        This returns a bare SHA1 object name for the current HEAD

        NB: if 'before' is specified, 'force' is ignored.
        """
        if before:
            print "git rev-list -n 1 --before='%s' HEAD"%before
            retcode, revision = utils.run2("git rev-list -n 1 --before='%s' HEAD"%before,
                                           show_command=False)
            print retcode, revision
            if retcode:
                if revision:
                    text = utils.indent(revision.strip(),'    ')
                else:
                    text = '    (it failed with return code %d)'%retcode
                raise GiveUp("%s\n%s"%(utils.wrap("%s:"
                    " \"git rev-list -n 1 --before='%s' HEAD\"'"
                    " could not determine a revision id for checkout:"%(co_leaf, before)),
                    text))
        else:
            retcode, revision = utils.run2('git rev-parse HEAD', show_command=False)
            if retcode:
                if revision:
                    text = utils.indent(revision.strip(),'    ')
                    if force:
                        if verbose:
                            print "'git rev-parse HEAD' had problems with checkout" \
                                  " '%s'"%co_leaf
                            print "    %s"%text
                            print "using original revision %s"%orig_revision
                        return orig_revision
                else:
                    text = '    (it failed with return code %d)'%retcode
                raise GiveUp("%s\n%s"%(utils.wrap("%s: 'git rev-parse HEAD'"
                    " could not determine a revision id for checkout:"%co_leaf),
                    text))
        return revision.strip()
예제 #5
0
파일: weld.py 프로젝트: Flameeyes/muddle
    def _calculate_revision(self, co_leaf, orig_revision):
        """
        This returns a bare SHA1 object name for orig_revision

        NB: if 'before' is specified, 'force' is ignored.
        """
        retcode, revision, ignore = utils.run3('git rev-parse %s'%orig_revision)
        if retcode:
            if revision:
                text = utils.indent(revision.strip(),'    ')
                raise GiveUp("%s\n%s"%(utils.wrap("%s: 'git rev-parse HEAD'"
                                                  " could not determine a revision id for checkout:"%co_leaf),
                                       text))
            else:
                raise GiveUp("%s\n"%(utils.wrap("%s: 'git rev-parse HEAD'"
                                                " could not determine a revision id for checkout:"%co_leaf)))
        return revision.strip()
예제 #6
0
파일: git.py 프로젝트: Flameeyes/muddle
    def _is_it_safe(self):
        """
        No dentists here...

        Raise an exception if there are (uncommitted) local changes or
        untracked files...
        """
        retcode, text= utils.run2("git status --porcelain", show_command=False)
        if retcode == 129:
            print "Warning: Your git does not support --porcelain; you should upgrade it."
            retcode, text = utils.run2("git status", show_command=False)
            if text.find("working directory clean") >= 0:
                text = ''

        if text:
            raise GiveUp("There are uncommitted changes/untracked files\n"
                         "%s"%utils.indent(text,'    '))
예제 #7
0
파일: git.py 프로젝트: crazyscot/muddle
    def _is_it_safe(self):
        """
        No dentists here...

        Raise an exception if there are (uncommitted) local changes or
        untracked files...
        """
        retcode, text = utils.run2("git status --porcelain",
                                   show_command=False)
        if retcode == 129:
            print "Warning: Your git does not support --porcelain; you should upgrade it."
            retcode, text = utils.run2("git status", show_command=False)
            if text.find("working directory clean") >= 0:
                text = ''

        if text:
            raise GiveUp("There are uncommitted changes/untracked files\n"
                         "%s" % utils.indent(text, '    '))
예제 #8
0
파일: weld.py 프로젝트: crazyscot/muddle
    def _calculate_revision(self, co_leaf, orig_revision):
        """
        This returns a bare SHA1 object name for orig_revision

        NB: if 'before' is specified, 'force' is ignored.
        """
        retcode, revision, ignore = utils.run3('git rev-parse %s' %
                                               orig_revision)
        if retcode:
            if revision:
                text = utils.indent(revision.strip(), '    ')
                raise GiveUp("%s\n%s" % (utils.wrap(
                    "%s: 'git rev-parse HEAD'"
                    " could not determine a revision id for checkout:" %
                    co_leaf), text))
            else:
                raise GiveUp("%s\n" % (utils.wrap(
                    "%s: 'git rev-parse HEAD'"
                    " could not determine a revision id for checkout:" %
                    co_leaf)))
        return revision.strip()
예제 #9
0
파일: git.py 프로젝트: Flameeyes/muddle
 def _git_describe_long(self, co_leaf, orig_revision, force=False, verbose=True):
     """
     This returns a "pretty" name for the revision, but only if there
     are annotated tags in its history.
     """
     retcode, revision = utils.run2('git describe --long', show_command=False)
     if retcode:
         if revision:
             text = utils.indent(revision.strip(),'    ')
             if force:
                 if verbose:
                     print "'git describe --long' had problems with checkout" \
                           " '%s'"%co_leaf
                     print "    %s"%text
                     print "using original revision %s"%orig_revision
                 return orig_revision
         else:
             text = '    (it failed with return code %d)'%retcode
         raise GiveUp("%s\n%s"%(utils.wrap("%s: 'git describe --long'"
             " could not determine a revision id for checkout:"%co_leaf),
             text))
     return revision.strip()
예제 #10
0
파일: bazaar.py 프로젝트: crazyscot/muddle
    def revision_to_checkout(self,
                             repo,
                             co_leaf,
                             options,
                             force=False,
                             before=None,
                             verbose=True):
        """
        Determine a revision id for this checkout, usable to check it out again.

        * 'co_leaf' should be the name of this checkout directory, for use
          in messages reporting what we are doing. Note that we are called
          already *in* that directory, though.

        If 'force' is true, then if we can't get one from bzr, and it seems
        "reasonable" to do so, use the original revision from the muddle
        depend file (if it is not HEAD).

        If 'before' is given, it should be a string describing a date/time, and
        the revision id chosen will be the last revision at or before that
        date/time.

        .. note:: This depends upon what the VCS concerned actually supports.
           This feature is experimental. XXX NOT YET IMPLEMENTED XXX

        'bzr revno' always returns a simple integer (or so I believe)

        'bzr version-info' returns several lines, including::

              revision-id: <something>
              revno: <xxx>

        where <xxx> is the same number as 'bzr revno', and <something>
        will be different depending on whether we're "the same" as the
        far repository.

        If the --check-clean flag is used, then there will also be a line
        of the form::

              clean: True

        indicating whether the source tree contains uncommitted changes
        (although not whether it is matching the far repository).

        So ideally we would (1) grumble if not clean, and (2) grumble
        if our revision id was different than after the last
        push/pull/checkout

        Well, 'bzr missing' should show unmerged/unpulled revisions
        between two branches, so if it ends "Branches are up to date"
        then that may be useful. Or no output with '-q' if they're OK.
        (needs to ignore stderr output, since I get that for mismatch
        in Bazaar network protocols)
        """

        env = self._derive_env()

        if before:
            # XXX For now, we're going to short-circuit everything else if we
            # XXX are asked for 'before'.
            try:
                return self._revision_id(env, 'before:date:%s' % before)
            except utils.GiveUp as e:
                raise utils.GiveUp('%s: %s' % (co_leaf, e))

        if repo.revision:
            orig_revision = repo.revision
        else:
            orig_revision = 'HEAD'

        # So, have we checked everything in?
        ok, cmd, txt = self._all_checked_in(env)
        if not ok:
            if force:
                print "'%s' reports checkout '%s' has uncommitted data" \
                        " (ignoring it)"%(cmd, co_leaf)
            else:
                raise utils.GiveUp("%s: '%s' reports"
                                   " checkout has uncommitted data" %
                                   (cmd, co_leaf))

        # So, is our current revision (on this local branch) also present
        # in the remote branch (our push/pull location)?
        missing, cmd = self._current_revision_missing(env)
        if missing:
            missing = missing.strip()
            if missing == 'bzr: ERROR: No peer location known or specified.':
                # This presumably means that they have never pushed since
                # the original checkout
                if force:
                    if all([x.isdigit() for x in orig_revision]):
                        if verbose:
                            print missing
                            print 'Using original revision: %s' % orig_revision
                        return orig_revision
                    else:
                        raise utils.GiveUp(
                            "%s: 'bzr missing' says '%s',\n"
                            "    and original revision is '%s', so"
                            " cannot use that" %
                            (co_leaf, missing[5:], orig_revision))
                else:
                    raise utils.GiveUp("%s: 'bzr missing' says '%s',\n"
                                       "    so cannot determine revision" %
                                       (co_leaf, missing[5:]))
            #elif missing.startswith("cannot import name install_lazy_named_hook"):
            #    print 'bzr says:'
            #    lines = missing.split('\n')
            #    for line in lines:
            #        print '   ', line
            #    print 'Assuming this is a problem with bzr itself, and ignoring it'
            #    print '(This is a horrible hack, until I find a better way round)'
            else:
                raise utils.GiveUp(
                    "%s: 'bzr missing' suggests this checkout revision"
                    " is not present in the remote repository:\n%s" %
                    (co_leaf, utils.indent(missing, '    ')))

        # So let's go with the revision id for the last commit of this local branch
        try:
            return self._revision_id(env, 'revno:-1')
        except utils.GiveUp as e:
            raise utils.GiveUp('%s: %s' % (co_leaf, e))
예제 #11
0
파일: bazaar.py 프로젝트: Flameeyes/muddle
    def revision_to_checkout(self, repo, co_leaf, options, force=False, before=None, verbose=True):
        """
        Determine a revision id for this checkout, usable to check it out again.

        * 'co_leaf' should be the name of this checkout directory, for use
          in messages reporting what we are doing. Note that we are called
          already *in* that directory, though.

        If 'force' is true, then if we can't get one from bzr, and it seems
        "reasonable" to do so, use the original revision from the muddle
        depend file (if it is not HEAD).

        If 'before' is given, it should be a string describing a date/time, and
        the revision id chosen will be the last revision at or before that
        date/time.

        .. note:: This depends upon what the VCS concerned actually supports.
           This feature is experimental. XXX NOT YET IMPLEMENTED XXX

        'bzr revno' always returns a simple integer (or so I believe)

        'bzr version-info' returns several lines, including::

              revision-id: <something>
              revno: <xxx>

        where <xxx> is the same number as 'bzr revno', and <something>
        will be different depending on whether we're "the same" as the
        far repository.

        If the --check-clean flag is used, then there will also be a line
        of the form::

              clean: True

        indicating whether the source tree contains uncommitted changes
        (although not whether it is matching the far repository).

        So ideally we would (1) grumble if not clean, and (2) grumble
        if our revision id was different than after the last
        push/pull/checkout

        Well, 'bzr missing' should show unmerged/unpulled revisions
        between two branches, so if it ends "Branches are up to date"
        then that may be useful. Or no output with '-q' if they're OK.
        (needs to ignore stderr output, since I get that for mismatch
        in Bazaar network protocols)
        """

        env = self._derive_env()

        if before:
            # XXX For now, we're going to short-circuit everything else if we
            # XXX are asked for 'before'.
            try:
                return self._revision_id(env, 'before:date:%s'%before)
            except utils.GiveUp as e:
                raise utils.GiveUp('%s: %s'%(co_leaf, e))

        if repo.revision:
            orig_revision = repo.revision
        else:
            orig_revision = 'HEAD'

        # So, have we checked everything in?
        ok, cmd, txt = self._all_checked_in(env)
        if not ok:
            if force:
                print "'%s' reports checkout '%s' has uncommitted data" \
                        " (ignoring it)"%(cmd, co_leaf)
            else:
                raise utils.GiveUp("%s: '%s' reports"
                                   " checkout has uncommitted data"%(cmd, co_leaf))

        # So, is our current revision (on this local branch) also present
        # in the remote branch (our push/pull location)?
        missing, cmd = self._current_revision_missing(env)
        if missing:
            missing = missing.strip()
            if missing == 'bzr: ERROR: No peer location known or specified.':
                # This presumably means that they have never pushed since
                # the original checkout
                if force:
                    if all([x.isdigit() for x in orig_revision]):
                        if verbose:
                            print missing
                            print 'Using original revision: %s'%orig_revision
                        return orig_revision
                    else:
                        raise utils.GiveUp("%s: 'bzr missing' says '%s',\n"
                                            "    and original revision is '%s', so"
                                            " cannot use that"%(co_leaf,
                                                                missing[5:],
                                                                orig_revision))
                else:
                    raise utils.GiveUp("%s: 'bzr missing' says '%s',\n"
                                        "    so cannot determine revision"%(co_leaf,
                                                                            missing[5:]))
            #elif missing.startswith("cannot import name install_lazy_named_hook"):
            #    print 'bzr says:'
            #    lines = missing.split('\n')
            #    for line in lines:
            #        print '   ', line
            #    print 'Assuming this is a problem with bzr itself, and ignoring it'
            #    print '(This is a horrible hack, until I find a better way round)'
            else:
                raise utils.GiveUp("%s: 'bzr missing' suggests this checkout revision"
                                    " is not present in the remote repository:\n%s"%(co_leaf,
                                    utils.indent(missing,'    ')))

        # So let's go with the revision id for the last commit of this local branch
        try:
            return self._revision_id(env, 'revno:-1')
        except utils.GiveUp as e:
            raise utils.GiveUp('%s: %s'%(co_leaf, e))