def test_git_p4_init(): options = argparse.Namespace() options.__setattr__("subcommand", "init") options.__setattr__("port", "localhost:1818") options.__setattr__("user", "g.pasieka") options.__setattr__("client", "test_depot_g.pasieka") options.__setattr__("passwd", "zaq12WSX") options.__setattr__("branch", "test-branch") options.__setattr__("root", None) options.__setattr__("nosync", False) options.__setattr__("sync", None) git_p4_init(options) if git_wrapper.get_current_branch() != options.branch: print "ERROR bad branch name after git-p4 init" return False if git_wrapper.check_head_CL_tag() == None: print "ERROR no tag on last commit" return False if len(git_wrapper.get_all_commits()) <= 1: print "ERROR some changelists were not commited" return False return True
def git_p4_sync(options): head_tag = git_wrapper.check_head_CL_tag() if head_tag == None: last_tag = git_wrapper.check_last_CL_tag() if last_tag != None: print str(git_wrapper.get_commit_distance(last_tag, "HEAD"))+\ " commits in this branch are not submitted to P4. Aborting p4 sync" return False p4w = p4_wrapper() p4w.load_state() #Login if not p4w.is_logged(): (p4port, p4user, p4client) = config_wrapper.get_branch_credentials(options.branch) res = p4w.p4_login(p4port, p4user, p4client, None) if not res: print "FATAL: Problem during login. Aborting git p4 sync" return False else: p4w.p4_client_read() #parse workspace mapping paths = [] #print p4w._p4config.get_all_properties() for depot_path in p4w._p4config._view.iterkeys(): if depot_path[1] != '-': paths.append(depot_path) #TODO: map changelist_no -> ws_path must be created to support mulit path commits #commit from changelist no commit_from_no = None commit_to_no = None commit_from_val = None if options.sync == None: commit_from = p4_changelist() commit_from_val = git_wrapper.get_last_commit()._descr if commit_from_val != None: commit_from.from_commit_msg(commit_from_val) commit_from_no = commit_from._ch_no else: commit_from_no = options.sync[0] if len(options.sync) == 2: commit_to_no = options.sync[1] path_changelist_dict = dict() for path in paths: (res, changelists) = p4w.p4_changelists(path, commit_from_no, commit_to_no) if commit_from_val != None: changelists = changelists[1:] path_changelist_dict[path] = changelists return _git_p4_sync(path_changelist_dict)