Esempio n. 1
0
class Clean(App):
    def __init__(self):
        self.repository = Repository()
        pass

    def getBranchesToDelete(self) -> [Branch]:
        remotes = self.repository.getRemotes()
        branches = self.repository.getBranches()

        branchesToDelete = []

        for branch in branches:
            deleteBranch = True
            for remote in remotes:
                if remote.hasBranch(branch):
                    deleteBranch = False

            if deleteBranch:
                branchesToDelete.append(branch)

        return branchesToDelete

    def deleteBranches(self, branches: [Branch] = []) -> bool:
        currentBranch = self.repository.getCurrentBranch()
        masterBranch = Branch(self.config.getMaster())

        for branch in branches:
            if branch.getName() == currentBranch.getName():
                currentBranch = self.repository.checkoutBranch(masterBranch)
            branch.delete()

        return True
Esempio n. 2
0
    def run(self, branch: [Branch, Tag]):
        remote = self.getRemote()
        repository = Repository()
        currentBranch = repository.getCurrentBranch()
        self.checkRepository()

        remote.compare(currentBranch, branch)
Esempio n. 3
0
class Clean(App):

    def __init__(self):
        self.repository = Repository()
        pass

    def getBranchesToDelete(self) -> [Branch]:
        remotes = self.repository.getRemotes()
        branches = self.repository.getBranches()

        branchesToDelete = []

        for branch in branches:
            deleteBranch = True
            for remote in remotes:
                if remote.hasBranch(branch):
                    deleteBranch = False

            if deleteBranch:
                branchesToDelete.append(branch)

        return branchesToDelete

    def deleteBranches(self, branches: [Branch] = []) -> bool:
        currentBranch = self.repository.getCurrentBranch()
        masterBranch = Branch(self.config.getMaster())

        for branch in branches:
            if branch.getName() == currentBranch.getName():
                currentBranch = self.repository.checkoutBranch(masterBranch)
            branch.delete()

        return True
Esempio n. 4
0
    def run(self, branch: Branch):
        repository = Repository()
        remote = self.getRemote()
        developmentBranches = repository.getDevelopmentBranches()
        if len(developmentBranches) == 1:
            developmentBranch = developmentBranches[0]
        else:
            branchNames = []
            for developmentBranch in developmentBranches:
                branchNames.append(developmentBranch.getName())

            branchNames.reverse()
            default = branchNames[0]
            choice = branchNames

            developmentBranch = Branch(
                self.interface.askFor("Which develop branch you want to use?",
                                      choice, default))

        remote.merge(developmentBranch, branch)
        repository.checkoutBranch(branch)
Esempio n. 5
0
    def run(self, branch: Branch):
        repository = Repository()
        remote = self.getRemote()
        developmentBranches = repository.getDevelopmentBranches()
        if len(developmentBranches) == 1:
            developmentBranch = developmentBranches[0]
        else:
            branchNames = []
            for developmentBranch in developmentBranches:
                branchNames.append(developmentBranch.getName())

            default = branchNames[0]
            choice = branchNames

            developmentBranch = Branch(self.interface.askFor(
                "Which develop branch you want to use?",
                choice,
                default
            ))

        remote.merge(developmentBranch, branch)
        repository.checkoutBranch(branch)
Esempio n. 6
0
 def checkout(self, remote: Remote, branch: Branch) -> bool:
     repository = Repository()
     repository.checkoutBranch(branch)
     remote.pull(branch)
     return True
Esempio n. 7
0
 def getDefaultBranch(self) -> [Branch, Tag]:
     repository = Repository()
     return repository.getLatestTag()
Esempio n. 8
0
 def instantiateRepository(self) -> bool:
     self.repository = Repository()
     return True
Esempio n. 9
0
class BaseCommand(object):

    interface = simpcli.Interface()
    config = GitcdConfig()
    configPersonal = GitcdPersonalConfig()
    updateRemote = False

    def __init__(self):
        self.instantiateRepository()
        if self.updateRemote is True:
            self.repository.update()

    def instantiateRepository(self) -> bool:
        self.repository = Repository()
        return True

    def run(self, branch: Branch):
        pass

    def getDefaultBranch(self) -> Branch:
        return self.repository.getCurrentBranch()

    def getRequestedBranch(self, branch: str) -> Branch:
        featureAsString = self.config.getString(self.config.getFeature())
        if not branch.startswith(featureAsString):
            branch = '%s%s' % (featureAsString, branch)
        return Branch(branch)

    def hasMultipleRemotes(self) -> bool:
        return len(self.repository.getRemotes()) > 1

    def getRemote(self) -> str:
        remotes = self.repository.getRemotes()

        if len(remotes) == 1:
            remote = remotes[0]
        else:
            if len(remotes) == 0:
                default = False
                choice = False
            else:
                default = remotes[0].getName()
                choice = []
                for remoteObj in remotes:
                    choice.append(remoteObj.getName())

            remoteAnswer = self.interface.askFor(
                "Which remote you want to use?", choice, default)
            for remoteObj in remotes:
                if remoteAnswer == remoteObj.getName():
                    remote = remoteObj

        return remote

    def checkTag(self, remote: Remote, tag: Tag) -> bool:
        if self.repository.hasUncommitedChanges():
            abort = self.interface.askFor(
                "You currently have uncomitted changes." +
                " Do you want me to abort and let you commit first?",
                ["yes", "no"], "yes")

            if abort == "yes":
                sys.exit(1)

        return True

    def checkRepository(self) -> bool:
        # check if repo has uncommited changes
        if self.repository.hasUncommitedChanges():
            abort = self.interface.askFor(
                "You currently have uncomitted changes." +
                " Do you want me to abort and let you commit first?",
                ["yes", "no"], "yes")

            if abort == "yes":
                sys.exit(1)

        return True

    def checkBranch(self, remote: Remote, branch: Branch) -> bool:
        # check if its a feature branch
        if not branch.isFeature():
            raise GitcdNoFeatureBranchException(
                "Your current branch is not a valid feature branch." +
                " Checkout a feature branch or pass one as param.")

        # check remote existence
        if not remote.hasBranch(branch):
            pushFeatureBranch = self.interface.askFor(
                "Your feature branch does not exists on remote." +
                " Do you want me to push it remote?", ["yes", "no"], "yes")

            if pushFeatureBranch == "yes":
                remote.push(branch)

        # check behind origin
        if remote.isBehind(branch):

            pushFeatureBranch = self.interface.askFor(
                "Your feature branch is ahead the origin/branch." +
                " Do you want me to push the changes?", ["yes", "no"], "yes")

            if pushFeatureBranch == "yes":
                remote.push(branch)

        return True

    def getTokenOrAskFor(self, tokenSpace: str) -> str:
        token = self.configPersonal.getToken(tokenSpace)
        if token is None:
            token = self.interface.askFor(
                "Your personal %s token?" % (tokenSpace), False, token)

            if (tokenSpace == 'bitbucket' and ':' not in token):
                self.interface.warning(
                    'For bitbucket you need to pass a username' +
                    ' as well like <username:app_password>')
                return self.getTokenOrAskFor(tokenSpace)

            self.configPersonal.setToken(tokenSpace, token)
            self.configPersonal.write()
        return token
Esempio n. 10
0
 def instantiateRepository(self) -> bool:
     self.repository = Repository()
     return True
Esempio n. 11
0
class BaseCommand(object):

    interface = simpcli.Interface()
    config = GitcdConfig()
    configPersonal = GitcdPersonalConfig()
    updateRemote = False

    def __init__(self):
        self.instantiateRepository()
        if self.updateRemote is True:
            self.repository.update()

    def instantiateRepository(self) -> bool:
        self.repository = Repository()
        return True

    def run(self, branch: Branch):
        pass

    def getDefaultBranch(self) -> Branch:
        return self.repository.getCurrentBranch()

    def getRequestedBranch(self, branch: str) -> Branch:
        featureAsString = self.config.getString(self.config.getFeature())
        if not branch.startswith(featureAsString):
            branch = '%s%s' % (featureAsString, branch)
        return Branch(branch)

    def getRemote(self) -> str:
        remotes = self.repository.getRemotes()

        if len(remotes) == 1:
            remote = remotes[0]
        else:
            if len(remotes) == 0:
                default = False
                choice = False
            else:
                default = remotes[0].getName()
                choice = []
                for remoteObj in remotes:
                    choice.append(remoteObj.getName())

            remoteAnswer = self.interface.askFor(
                "Which remote you want to use?",
                choice,
                default
            )
            for remoteObj in remotes:
                if remoteAnswer == remoteObj.getName():
                    remote = remoteObj

        return remote

    def checkTag(self, remote: Remote, tag: Tag) -> bool:
        if self.repository.hasUncommitedChanges():
            abort = self.interface.askFor(
                "You currently have uncomitted changes." +
                " Do you want me to abort and let you commit first?",
                ["yes", "no"],
                "yes"
            )

            if abort == "yes":
                sys.exit(1)

        return True

    def checkRepository(self) -> bool:
        # check if repo has uncommited changes
        if self.repository.hasUncommitedChanges():
            abort = self.interface.askFor(
                "You currently have uncomitted changes." +
                " Do you want me to abort and let you commit first?",
                ["yes", "no"],
                "yes"
            )

            if abort == "yes":
                sys.exit(1)

        return True

    def checkBranch(self, remote: Remote, branch: Branch) -> bool:
        # check if its a feature branch
        if not branch.isFeature():
            raise GitcdNoFeatureBranchException(
                "Your current branch is not a valid feature branch." +
                " Checkout a feature branch or pass one as param."
            )

        # check remote existence
        if not remote.hasBranch(branch):
            pushFeatureBranch = self.interface.askFor(
                "Your feature branch does not exists on remote." +
                " Do you want me to push it remote?", ["yes", "no"], "yes"
            )

            if pushFeatureBranch == "yes":
                remote.push(branch)

        # check behind origin
        if remote.isBehind(branch):

            pushFeatureBranch = self.interface.askFor(
                "Your feature branch is ahead the origin/branch." +
                " Do you want me to push the changes?",
                ["yes", "no"],
                "yes"
            )

            if pushFeatureBranch == "yes":
                remote.push(branch)

        return True

    def getTokenOrAskFor(self, tokenSpace: str) -> str:
        token = self.configPersonal.getToken(tokenSpace)
        if token is None:
            token = self.interface.askFor(
                "Your personal %s token?" % (tokenSpace),
                False,
                token
            )

            if (
                tokenSpace == 'bitbucket' and
                ':' not in token
            ):
                self.interface.warning(
                    'For bitbucket you need to pass a username' +
                    ' as well like <username:app_password>'
                )
                return self.getTokenOrAskFor(tokenSpace)

            self.configPersonal.setToken(tokenSpace, token)
            self.configPersonal.write()
        return token
Esempio n. 12
0
 def __init__(self):
     self.repository = Repository()
     pass
Esempio n. 13
0
 def checkout(self, remote: Remote, branch: Branch) -> bool:
     repository = Repository()
     repository.checkoutBranch(branch)
     remote.pull(branch)
     return True
Esempio n. 14
0
 def __init__(self):
     self.repository = Repository()
     pass