예제 #1
0
def add_file_commit(entity, file_, repo, log, git_name, git_mail, agent):
    log.ok('add_file_commit(%s, %s, %s, %s, %s, %s)' % (file_, repo, log, git_name, git_mail, agent))
    staged = dvcs.list_staged(repo)
    modified = dvcs.list_modified(repo)
    if staged and not modified:
        log.ok('All files staged.')
        log.ok('Updating changelog')
        path = file_.path_abs.replace('{}/'.format(entity.path), '')
        changelog_messages = ['Added entity file {}'.format(path)]
        if agent:
            changelog_messages.append('@agent: %s' % agent)
        changelog.write_changelog_entry(
            entity.changelog_path, changelog_messages, git_name, git_mail)
        log.ok('git add %s' % entity.changelog_path_rel)
        git_files = [entity.changelog_path_rel]
        dvcs.stage(repo, git_files)
        
        log.ok('Committing')
        commit = dvcs.commit(repo, 'Added entity file(s)', agent)
        log.ok('commit: {}'.format(commit.hexsha))
        committed = dvcs.list_committed(repo, commit)
        committed.sort()
        log.ok('files committed:')
        for f in committed:
            log.ok('| %s' % f)
        
    else:
        log.not_ok('%s files staged, %s files modified' % (len(staged),len(modified)))
        log.not_ok('staged %s' % staged)
        log.not_ok('modified %s' % modified)
        log.not_ok('Can not commit!')
        raise Exception('Could not commit bc %s unstaged files: %s' % (len(modified), modified))
    return file_,repo,log
예제 #2
0
def add_file_commit(entity, file_, repo, log, git_name, git_mail, agent):
    log.ok('add_file_commit(%s, %s, %s, %s, %s, %s)' % (file_, repo, log, git_name, git_mail, agent))
    staged = dvcs.list_staged(repo)
    modified = dvcs.list_modified(repo)
    if staged and not modified:
        log.ok('All files staged.')
        log.ok('Updating changelog')
        path = file_.path_abs.replace('{}/'.format(entity.path), '')
        changelog_messages = ['Added entity file {}'.format(path)]
        if agent:
            changelog_messages.append('@agent: %s' % agent)
        changelog.write_changelog_entry(
            entity.changelog_path, changelog_messages, git_name, git_mail)
        log.ok('git add %s' % entity.changelog_path_rel)
        git_files = [entity.changelog_path_rel]
        dvcs.stage(repo, git_files)
        
        log.ok('Committing')
        commit = dvcs.commit(repo, 'Added entity file(s)', agent)
        log.ok('commit: {}'.format(commit.hexsha))
        committed = dvcs.list_committed(repo, commit)
        committed.sort()
        log.ok('files committed:')
        for f in committed:
            log.ok('| %s' % f)
        
    else:
        log.not_ok('%s files staged, %s files modified' % (len(staged),len(modified)))
        log.not_ok('staged %s' % staged)
        log.not_ok('modified %s' % modified)
        log.not_ok('Can not commit!')
        raise Exception('Could not commit bc %s unstaged files: %s' % (len(modified), modified))
    return file_,repo,log
예제 #3
0
def repo_status(repo, log):
    """Logs staged, modified, and untracked files and returns same
    
    @param repo
    @param log
    @returns: staged,modified,untracked
    """
    log.ok('| %s' % repo)
    staged = dvcs.list_staged(repo)
    modified = dvcs.list_modified(repo)
    untracked = dvcs.list_untracked(repo)
    log.ok('|   %s staged, %s modified, %s untracked' % (
        len(staged), len(modified), len(untracked),
    ))
    for path in staged:
        log.ok('|   staged: %s' % path)
    for path in modified:
        log.ok('|   modified: %s' % path)
    for path in untracked:
        log.ok('|   untracked: %s' % path)
    return staged, modified, untracked
예제 #4
0
 def check_repository(cidentifier):
     """Load repository, check for staged or modified files
     
     Entity.add_files will not work properly if the repo contains staged
     or modified files.
     
     Results dict includes:
     - 'passed': boolean
     - 'repo': GitPython repository
     - 'staged': list of staged files
     - 'modified': list of modified files
     
     @param cidentifier: Identifier
     @returns: dict
     """
     logging.info('Checking repository')
     passed = False
     repo = dvcs.repository(cidentifier.path_abs())
     logging.info(repo)
     staged = dvcs.list_staged(repo)
     if staged:
         logging.error('*** Staged files in repo %s' % repo.working_dir)
         for f in staged:
             logging.error('*** %s' % f)
     modified = dvcs.list_modified(repo)
     if modified:
         logging.error('Modified files in repo: %s' % repo.working_dir)
         for f in modified:
             logging.error('*** %s' % f)
     if repo and (not (staged or modified)):
         passed = True
         logging.info('ok')
     else:
         logging.error('FAIL')
     return {
         'passed': passed,
         'repo': repo,
         'staged': staged,
         'modified': modified,
     }