当前位置: 首页>>代码示例>>Python>>正文


Python Repo.is_dirty方法代码示例

本文整理汇总了Python中git.Repo.is_dirty方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.is_dirty方法的具体用法?Python Repo.is_dirty怎么用?Python Repo.is_dirty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.is_dirty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_commit_if_possible

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def get_commit_if_possible(filename):
    """Try to retrieve VCS information for a given file.

    Currently only supports git using the gitpython package.

    Parameters
    ----------
    filename : str

    Returns
    -------
        path: str
            The base path of the repository
        commit: str
            The commit hash
        is_dirty: bool
            True if there are uncommitted changes in the repository
    """
    # git
    if opt.has_gitpython:
        from git import Repo, InvalidGitRepositoryError
        try:
            directory = os.path.dirname(filename)
            repo = Repo(directory, search_parent_directories=True)
            try:
                path = repo.remote().url
            except ValueError:
                path = 'git:/' + repo.working_dir
            is_dirty = repo.is_dirty()
            commit = repo.head.commit.hexsha
            return path, commit, is_dirty
        except InvalidGitRepositoryError:
            pass
    return None, None, None
开发者ID:elanmart,项目名称:sacred,代码行数:36,代码来源:dependencies.py

示例2: closeEvent

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
    def closeEvent(self, event):
        """
            Catching the close event to do some cleanup
        """
        def run_command(command):
            handle = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
            handle.wait()

        a_repo = Repo(self._directory)
        os.chdir(self._directory)

        try:
            active_branch_name = a_repo.active_branch.name
            should_be_cleaned = a_repo.active_branch.name == 'gitbuster_rebase'
        except TypeError:
            should_be_cleaned = True

        if should_be_cleaned:
            if a_repo.is_dirty():
                run_command("git reset --hard")

            fallback_branch_name = [branch.name for branch in a_repo.branches
                                    if branch.name != 'gitbuster_rebase'][0]
            run_command("git checkout %s" % fallback_branch_name)
            run_command("git branch -D gitbuster_rebase")
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:27,代码来源:main_window.py

示例3: main

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def main():
    log = logging.getLogger(__name__)
    commit_msg = 'auto-save'
    if len(sys.argv) >= 2:
        commit_msg = sys.argv[1]
    log.info('commit_msg %s', commit_msg)
    
    commit_cnt = 0
    repo_path = abspath(curdir)
    log.info('repo_path %s', repo_path)
    repo = Repo(repo_path)

    while True:
        if repo.is_dirty():
            log.info('repo is dirty')
            # refresh all_files, so that external 'git add'-ed files are included too
            all_files = []
            for ent in repo.index.entries:
                filename = ent[0]
                log.debug('adding file %s', filename)
                all_files.append(filename)
            # add and commit
            repo.index.add(all_files)
            log.info('repo commit')
            repo.index.commit(commit_msg + '-' + str(commit_cnt))
            commit_cnt += 1
        sleep(1)
开发者ID:justinc1,项目名称:git-wiki-autorefresh,代码行数:29,代码来源:git-wiki-autorefresh.py

示例4: __get_branch

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
    def __get_branch(self, path):
        """Gets required information of a repository

        :param path: Path of .git directory
        :return: Config dictionary
        """
        info = {}
        try:
            repo = Repo(path)
            info.update({'path': str(os.path.dirname(path)),
                         'branch': str(repo.head.ref),
                         'commit': str(repo.head.reference.commit),
                         'is_dirty': repo.is_dirty(),
                         'name': name_from_url(str(repo.remotes[0].url)),
                         'depth': 1,
                         'type': "git"})
            urls = {}
            remotes = repo.remotes
            for each in remotes:
                urls.update({each.name: each.url})
            info.update({'repo_url': urls})
        except Exception as e:
            self.logger.error(e)
            return {0: str(e)}
        return info
开发者ID:ruiztulio,项目名称:backupws,代码行数:27,代码来源:git_branch.py

示例5: update_repository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def update_repository(path, branch, logger):
    try:
        repository = Repo(path)

        if repository.bare:
            logger.warn("\"%s\" is a bare git repository, skipping", path)
            return False

        if repository.is_dirty():
            logger.warn("\"%s\" has unsaved changes, skipping", path)
            return False

        branches = repository.branches
        # noinspection PyTypeChecker
        for b in branches:
            if b.name == branch:
                logger.info("Updating \"%s\"", path)
                b.checkout()
                origin = repository.remote()
                origin.pull()
                return True
            else:
                logger.info("\"%s\" does not have a %s branch, skipping", path, branch)
                return False
    except InvalidGitRepositoryError:
        logger.warn("\"%s\" is not a valid git repository, skipping", path)
        return False
    except GitCommandError:
        logger.exception("Failed to update \"%s\"", path)
        return False
开发者ID:ldalamagas,项目名称:git-puller,代码行数:32,代码来源:shell.py

示例6: __start_experiment

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
    def __start_experiment(self, parameters):
        """
        Start an experiment by capturing the state of the code
        :param parameters: a dictionary containing the parameters of the experiment
        :type parameters: dict
        :return: the tag representing this experiment
        :rtype: TagReference
        """
        repository = Repo(self.__repository_directory, search_parent_directories=True)
        if len(repository.untracked_files) > 0:
            logging.warning("Untracked files will not be recorded: %s", repository.untracked_files)
        current_commit = repository.head.commit
        started_state_is_dirty = repository.is_dirty()

        if started_state_is_dirty:
            repository.index.add([p for p in self.__get_files_to_be_added(repository)])
            commit_obj = repository.index.commit("Temporary commit for experiment " + self.__experiment_name)
            sha = commit_obj.hexsha
        else:
            sha = repository.head.object.hexsha

        data = {"parameters": parameters, "started": time.time(), "description": self.__description,
                "commit_sha": sha}
        tag_object = self.__tag_repo(data, repository)

        if started_state_is_dirty:
            repository.head.reset(current_commit, working_tree=False, index=True)

        return tag_object
开发者ID:mallamanis,项目名称:experimenter,代码行数:31,代码来源:experimentlogger.py

示例7: create_new_working_branch

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def create_new_working_branch(branch, base, remote_name):

    repo = Repo(get_project_root())
    remote = repo.remotes[remote_name]

    if repo.is_dirty() == True:
        print "The working tree contains uncommitted changes, commit or stash "
        print "these and try again."
        return 1

    try:
        head = repo.create_head(branch, base)
        print "Summary of actions:"
        print "- A new branch " + branch + " was created, based on " + base + "."
    except OSError:
        print "A branch " + branch + " already exists!"
        return 1

    ret = remote.push(head)
    info = ret[0]
    print ("- A new remote branch " + branch + " was created on " +
           remote_name + ".")

    head.set_tracking_branch(info.remote_ref)
    print ("- Branch " + branch + " tracks remote branch " + branch +
           " from " + remote_name + ".")

    head.checkout()

    print "- You are now on branch " + branch + "."

    return 0
开发者ID:ChrisCummins,项目名称:pip-db,代码行数:34,代码来源:pipbot.py

示例8: __init__

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
    def __init__(self, model, methods, nvot, ncand, niter,
            baseName = None, media=truth, seed=None, force=False):
        """A harness function which creates niter elections from model and finds three kinds
        of utility for all methods given.

        for instance:

        >>> csvs = CsvBatch(PolyaModel(), [[Score(), baseRuns], [Mav(), medianRuns]], nvot=5, ncand=4, niter=3)
        >>> len(csvs.rows)
        54
        """
        rows = []
        emodel = str(model)
        if (seed is None):
            seed = (baseName or '') + str(niter)
            self.seed = seed
        random.seed(seed)
        try:
            from git import Repo
            repo = Repo(os.getcwd())
            if not force:
                assert not repo.is_dirty()
            self.repo_version = repo.head.commit.hexsha
        except:
            self.repo_version = 'unknown repo version'
        for i in range(niter):
            eid = uuid4()
            electorate = model(nvot, ncand)
            for method, chooserFuns in methods:
                results = method.resultsTable(eid, emodel, ncand, electorate, chooserFuns, media=media)
                rows.extend(results)
            debug(i,results[1:3])
        self.rows = rows
        if baseName:
            self.saveFile(baseName)
开发者ID:The-Center-for-Election-Science,项目名称:vse-sim,代码行数:37,代码来源:vse.py

示例9: close_working_branch

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def close_working_branch(branch, remote_name):

    repo = Repo(get_project_root())
    remote = repo.remotes[remote_name]

    if repo.is_dirty() == True:
        print "The working tree contains uncommitted changes, commit or stash "
        print "these and try again."
        return 1

    print "Summary of actions:"
    master = repo.heads.master
    master.checkout()

    repo.git.merge(branch, '--no-ff')
    print ("- Branch " + branch + " was merged into master.")

    repo.delete_head(branch, force=True)
    print ("- Branch " + branch + " was deleted.")

    ret = remote.push(":" + branch)
    print ("- Remote branch " + branch + " on " + remote_name + " was deleted.")

    remote.push(master)
    print ("- Merged changes on master were pushed to " + remote_name + ".")

    print "- You are now on branch master."

    return 0
开发者ID:ChrisCummins,项目名称:pip-db,代码行数:31,代码来源:pipbot.py

示例10: get_current_commit

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
    def get_current_commit():
        repo = Repo(os.curdir)

        if not repo or repo.is_dirty():
            return None

        # Retrieve latest commit
        return repo.head.commit
开发者ID:fuzeman,项目名称:Plex-Trakt-Scrobbler,代码行数:10,代码来源:build.py

示例11: is_repo_dirty

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def is_repo_dirty(repo_path=None):
    """Returns human readable unicode icon if a repo has uncommited files or not."""
    try:
        repo = Repo(repo_path)
        if repo.is_dirty(untracked_files=True) == True:
            return u'[\u2717]'
        return u'[\u2713]'
    except InvalidGitRepositoryError:
        return "[?]"
开发者ID:drerik,项目名称:docker-python-utils,代码行数:11,代码来源:gitcheck.py

示例12: main

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def main(args):
    with open(os.path.expanduser(args.config_file), 'r') as fh:
        config = yaml.load(fh)

    # Create an archive
    dirname = get_dirname(args.repo)
    
    logger.info("Using repo {}".format(dirname))

    repo = Repo(args.repo)
    assert not repo.is_dirty()

    archive_name = dirname
    git_tag = next((tag for tag in repo.tags if tag.commit == repo.head.commit), None)
    if git_tag:
        archive_name += '_' + git_tag    

    else:
        archive_name += '_' + repo.head.object.hexsha

    if args.extra_tag:
        archive_name += '_' + args.extra_tag

    logger.info("Creating repo archive {}".format(archive_name))
    archive = "{0}.tar.gz".format(archive_name)
    archive_path = ospj(args.repo, archive)

    run_dir = os.getcwd()
    os.chdir(args.repo)
    os.system("git-archive-all {}".format(archive))
    os.chdir(run_dir)

    logger.info("Archive created.")

    # Transfer archive to remote
    remote_dir = config['hosts']['irma']['archive_dir']

    Connection('irma').put(archive_path, remote=remote_dir)
    logger.info("Archive successfully transferred to irma")

    # Extract remote archive
    c = Connection('irma')     
    remote_archive_path = ospj(remote_dir, archive)
    remote_extracted_path = remote_archive_path.replace('.tar.gz', '')

    c.run('rm -r {} || true'.format(remote_extracted_path))
    c.run('cd {}; tar -xvzf {}'.format(remote_dir, remote_archive_path))

    # Create a link from dev or latest to the new archive
    if args.mode == 'dev': 
        link_name = "{}_dev".format(dirname)
    else:
        link_name = "{}_latest".format(dirname)
    c.run('cd {}; ln -sfn {} {}'.format(remote_dir, remote_extracted_path, link_name))
    logger.info("Linking: {} {}".format(remote_extracted_path, link_name))
    logger.info("{} successfully linked as the new {}".format(dirname, link_name))
开发者ID:alneberg,项目名称:bu,代码行数:58,代码来源:transfer_repo_to_irma.py

示例13: main

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
def main():
    " This method launches gitbuster."
    app = QApplication(sys.argv)

    if len(sys.argv) == 2 and is_top_git_directory(sys.argv[1]):
        filepath = os.path.abspath(sys.argv[1])
    else:
        filepath = select_git_directory()

    if not filepath:
        sys.exit(1)

    test_repo = Repo(filepath)
    if os.path.exists(os.path.join(filepath, ".git/rebase-merge")):
        # Special conflict mode
        os.chdir(filepath)
        orig_hexsha = open(".git/rebase-merge/head").read().strip()
        conflict_hexsha = open(".git/rebase-merge/stopped-sha").read().strip()
        unmerged_files = get_unmerged_files(conflict_hexsha, orig_hexsha,
                                            filepath)
        conflicts_dialog = ConflictsDialog(unmerged_files)
        ret = conflicts_dialog.exec_()
        if ret:
            solutions = conflicts_dialog.get_solutions()
            apply_solutions(solutions)
            print "Applied your solutions, you can now continue:"
            print "git rebase --continue"
        sys.exit()

    if test_repo.is_dirty():
        warning_title = "Unclean repository"
        warning_text = "The chosen repository has unstaged changes. " \
                       "You should commit or stash them. "\
                       "Do you want to continue anyway ?"
        warning_choice = QMessageBox.warning(None, warning_title,
                                             warning_text,
                                             "Yes",
                                             button1Text="No",
                                             button2Text ="Stash")

        if warning_choice == 1:
            sys.exit(2)
        elif warning_choice == 2:
            test_repo.git.stash()

    window = MainWindow(directory=filepath, debug=True)
    window.show()

    #reroute SIGINT to Qt.
    def quit(signum, frame):
        # Clean the repo : stages, tmp_rebase, remotes
        window._ui.actionQuit.trigger()
    signal.signal(signal.SIGINT, quit)

    #run app and exit with same code
    sys.exit(app.exec_())
开发者ID:mike-perdide,项目名称:gitbuster,代码行数:58,代码来源:__init__.py

示例14: get_status

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
 def get_status(self):
     # if self.config['revision_control_system'] != 'git':
     # config = self.inv_namespace.configuration()
     if self.config['revision_control_system'] != 'git':
         return ''
     from git import Repo
     repo = Repo(self.root_dir)
     s = str(repo.active_branch)
     if repo.is_dirty():
         s += "!"
     return s
开发者ID:lino-framework,项目名称:atelier,代码行数:13,代码来源:projects.py

示例15: commit_changes

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_dirty [as 别名]
 def commit_changes(repo: Repo, to_commit: "List[str]",  message: str=None):
     # TODO: doesn't exists before the first commit, handle exception here
     # import ipdb; ipdb.set_trace()
     # if repo.head.commit.diff():
     if repo.is_dirty():
         repo.index.add(to_commit)
         msg = message or "Autocommit of {}".format(", ".join(to_commit))
         repo.index.commit(msg)
     else:
         log.debug("Nothing to commit Repo: {}, to_commit: {}, message: {}"
                   .format(repo, to_commit, message))
开发者ID:asamalik,项目名称:cdic,代码行数:13,代码来源:git.py


注:本文中的git.Repo.is_dirty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。