コード例 #1
0
ファイル: gitdb.py プロジェクト: cb22/gitdb
def post_checkout_branch(branch, database, old_head_ref, new_head_ref):
    """\
    Handle a switch in branches. Fun times ahead.
    """
    if get_last_branch() == branch:
        logging.warning("Already on branch %s.", branch)
        return
     
    # Still a work in progress           
    #check_branch_rename(branch, database)

    if not exists_database(database + branch): 
        # The branched DB doesn't exist, create it from our current copy.
        # XXX: This has problems! Currently we only support branching from the current branch...
        # I think I can solve this by searching through all the branches, and finding the corresponding name
        # for old_ref.
        src_branch = get_last_branch()
        copy_database(database, database + branch)
        
        # Create the "base.sql" file for this branch - any changes to the branch will be relative to its starting
        # point - and NOT to production.
        create_base_sql(branch, database)
        
        patches = [patch for patch in list_applied_patches(src_branch, database) if patch not in list_merged_patches(src_branch, branch, database) and patch not in list_ignored_patches(src_branch, database)]
        add_merged_patches(patches, 'base.sql', src_branch, branch, database)
        

    # XXX: Use reflog here rather to get the last branch.
    rename_database(database, database + get_last_branch())
    rename_database(database + branch, database)
    
    set_last_branch(branch)
    add_event_to_db(database, "branch-change", time.time())
コード例 #2
0
ファイル: gitdb.py プロジェクト: cb22/gitdb
def check_branch_rename(current_branch, database):
    if not exists_database(database + current_branch):
        for line in git.reflog(True):
            res = re.search(line, r".* Branch: renamed refs/heads/(\w+) to refs/heads/%s" % current_branch)
            if res:
                old_branch_name = res.group(1)
                logging.info("Detected that branch we are working on, '%s', used to be called '%s'.", current_branch, old_branch_name)
                
                # Rename the database, as well as any SQL patch files, etc, and rewrite our sqlite data.
                rename_database(database + old_branch_name, database + current_branch)
                
                break