Exemple #1
0
    def show_my_commits(self, show_sha, since_days):
        list_of_repos = self.config.getlist('git_repo', 'repo')
        for repo in list_of_repos:
            current_repo_path = self.path_to_workspace + os.sep + repo
            if os.path.exists(current_repo_path):

                if since_days is None:
                    commit_since_days = self.config.getint(
                        'git_repo', 'commit_since_days')
                else:
                    commit_since_days = int(since_days)
                since_date = datetime.now() - timedelta(days=commit_since_days)
                show_commit = ''
                if not show_sha:
                    show_commit = '\|commit '
                cmd_commits = 'cd ' + current_repo_path + ';git log --author="$(git config user.name)" --since "{0} {1} {2}"|grep -v "Author:\|Date:{3}"'.\
                        format(since_date.strftime("%B"), since_date.day, since_date.year, show_commit)
                commits_output = EnvironmentBuilder.handle_command(
                    cmd_commits, False, True, self.print_cmd_output,
                    self.print_cmd)
                p_status, output, err = commits_output
                if p_status == 0 and not (output.rstrip('\n').isspace()):
                    output = os.linesep.join(
                        ['\t' + s.strip() for s in output.splitlines() if s])
                    ColorPrint.blue_highlight(
                        "Commits for repository [{0}]".format(repo.upper()))
                    ColorPrint.info(output)

                unpushed_commits = self.get_unpushed_commits(current_repo_path)
                if unpushed_commits and not unpushed_commits.rstrip(
                        '\n').isspace():
                    ColorPrint.err("\tUnpushed commits!!!")
                    ColorPrint.warn(unpushed_commits)
Exemple #2
0
 def _git_custom(self, git_command, repo):
     ColorPrint.blue_highlight(
         "Running custom git command on repository [{0}]".format(repo))
     repo_path = self.path_to_workspace + os.sep + repo
     if os.path.exists(repo_path):
         self.run_command_and_collect_errors('cd {0};git {1}'.format(
             repo_path, git_command))
     else:
         ColorPrint.warn(
             "The repository path [{0}] is not available".format(repo))
Exemple #3
0
    def _git_pull(self, repo):
        ColorPrint.blue_highlight("Pulling the repository [{0}]".format(repo))
        repo_path = self.path_to_workspace + os.sep + repo
        is_git_pull_ran = False
        if os.path.exists(repo_path):
            current_branch = self.get_branch_name(repo_path)
            if self._is_branch_up_to_date(repo_path):
                if repo in self.repo_status and self.repo_status[repo]:
                    ColorPrint.blue_highlight(
                        'Your repository [{0}] is up-to-date, skipping [git pull]'
                        .format(repo))
                else:
                    p_status, output, error = self.run_command_and_collect_errors(
                        'cd {0};git pull origin {1}'.format(
                            repo_path, current_branch))
                    is_git_pull_ran = True
            else:
                self.run_git_stash(repo_path)
                if self._is_ready_to_pull(repo_path):
                    if repo in self.repo_status and self.repo_status[repo]:
                        ColorPrint.blue_highlight(
                            'Your repository [{0}] is up-to-date, skipping [git pull]'
                            .format(repo))
                    else:
                        p_status, output, error = self.run_command_and_collect_errors(
                            'cd {0};git pull origin {1}'.format(
                                repo_path, current_branch))
                        is_git_pull_ran = True
                self.run_git_unstash(repo_path)
        else:
            ColorPrint.warn(
                "The repository path [{0}] is not available".format(repo))

        if is_git_pull_ran and p_status == 0:
            if 'up to date' in output or 'Successfully rebased and updated' or 'Fast-forward' in output:
                ColorPrint.blue_highlight(
                    "Pull for repository {0} finished successfully".format(
                        repo))
            else:
                current_error = "Your repository {0} is broken, try to run 'git gc --prune=now' and 'git remote prune origin' to fix it".format(
                    repo)
                ColorPrint.err(current_error)
                filename = 'errors.txt'
                if os.path.exists(filename):
                    append_write = 'a'  # append if already exists
                else:
                    append_write = 'w'  # make a new file if not
                error_file = open(filename, append_write)
                error_file.write(current_error + '\n')
                error_file.close()