Esempio n. 1
0
 def __init__(self, pathleft, pathright, pathjson, accleft="", pwdleft="", accright="", pwdright="", accjson="", pwdjson=""):
     self.pathleft = pathleft
     self.pathright = pathright
     self.pathjson = pathjson
     self.json = {}
     self.LoadJson()
     self.left_wc = pysvn.SvnWorkingCopy(self.pathleft, acc=accleft, pwd=pwdleft)
     self.right_wc = pysvn.SvnWorkingCopy(self.pathright, acc=accright, pwd=pwdright)
     self.json_wc = None
     self.accjson = accjson
     self.pwdjson = pwdjson
Esempio n. 2
0
 def DumpJson(self, commit=True):
     self.ClearJump()
     with open(self.pathjson, 'w') as f:
         json.dump(self.json, f, indent=4)
     if not self.json_wc:
         if not pysvn.is_workingcopy(self.pathjson) and pysvn.is_workingcopy(os.path.dirname(self.pathjson)):
             pysvn.svnadd(self.pathjson)
         if pysvn.is_workingcopy(self.pathjson):
             self.json_wc = pysvn.SvnWorkingCopy(self.pathjson, acc=self.accjson, pwd=self.pwdjson)
     if self.json_wc and commit:
         self.json_wc.commit('sync json')
Esempio n. 3
0
def test_svnlog():
    test_repocreate()
    wc1 = pysvn.SvnWorkingCopy(PATH_WC1, URL_REPO1, acc='acc1', pwd='pwd1')
    wc1.checkout()
    wc2 = pysvn.SvnWorkingCopy(PATH_WC2, URL_REPO2, acc='acc2', pwd='pwd2')
    wc2.checkout()

    # add something to wc1
    create_path(PATH_SYNC1)
    create_file(os.path.join(PATH_SYNC1, 'text01.txt'), 'text01')
    create_path(os.path.join(PATH_SYNC1, 'sub00'))
    create_path(os.path.join(PATH_SYNC1, 'sub01'))
    create_file(os.path.join(PATH_SYNC1, 'sub01/text01.txt'), 'text01')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text03.txt'), 'text03')
    create_path(os.path.join(PATH_SYNC1, 'sub02'))
    create_file(os.path.join(PATH_SYNC1, 'sub02/bin02.a'), 'bin02')
    create_path(os.path.join(PATH_SYNC1, '中文目录03'))
    create_file(os.path.join(PATH_SYNC1, '中文目录03/bin03.a'), 'bin03')
    wc1.full_modify()
    wc1.commit('init')
    wc1ex = pysvn.SvnWorkingCopy(PATH_WC1_EX,
                                 URL_REPO1,
                                 acc='acc1',
                                 pwd='pwd1')
    wc1ex.checkout()

    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text01.txt'), 'append left')
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text03.txt'), 'append left')
    remove_file(os.path.join(PATH_SYNC1_EX, 'sub02/bin02.a'))
    create_file(os.path.join(PATH_SYNC1_EX, 'sub02/bin02.a'), 'wtf\n' * 100)
    wc1ex.propset(os.path.join(PATH_SYNC1_EX, 'sub00'), 'svn:ignore',
                  'ignore001')
    # remove_path(os.path.join(PATH_SYNC1_EX, '中文目录03'))
    wc1ex.full_modify()
    wc1ex.commit('modify')

    wc1.update()
    print(wc1.log([(1, 2)])[1])
Esempio n. 4
0
def test_merge_withsolve(reverse=False):
    test_repocreate()
    wc1 = pysvn.SvnWorkingCopy(PATH_WC1, URL_REPO1, acc='acc1', pwd='pwd1')
    wc1.checkout()
    wc2 = pysvn.SvnWorkingCopy(PATH_WC2, URL_REPO2, acc='acc2', pwd='pwd2')
    wc2.checkout()

    # add something to wc1
    create_path(PATH_SYNC1)
    create_file(os.path.join(PATH_SYNC1, 'text01.txt'), 'text01')
    create_path(os.path.join(PATH_SYNC1, 'sub00'))
    create_path(os.path.join(PATH_SYNC1, 'sub01'))
    create_file(os.path.join(PATH_SYNC1, 'sub01/text01.txt'), 'text01')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text03.txt'), 'text03')
    create_path(os.path.join(PATH_SYNC1, 'sub02'))
    create_file(os.path.join(PATH_SYNC1, 'sub02/bin02.a'), 'bin02')
    create_path(os.path.join(PATH_SYNC1, '中文目录03'))
    create_file(os.path.join(PATH_SYNC1, '中文目录03/bin03.a'), 'bin03')
    wc1.full_modify()
    wc1.commit('init')
    wc1ex = pysvn.SvnWorkingCopy(PATH_WC1_EX,
                                 URL_REPO1,
                                 acc='acc1',
                                 pwd='pwd1')
    wc1ex.checkout()
    # add something to wc2
    create_path(PATH_SYNC2)
    create_file(os.path.join(PATH_SYNC2, 'text01.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'text02.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub000'))
    create_path(os.path.join(PATH_SYNC2, 'sub01'))
    create_file(os.path.join(PATH_SYNC2, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'sub01/text03.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub03'))
    create_file(os.path.join(PATH_SYNC2, 'sub03/bin03.a'), 'bin03')
    wc2.full_modify()
    wc2.commit('init')
    wc2ex = pysvn.SvnWorkingCopy(PATH_WC2_EX,
                                 URL_REPO2,
                                 acc='acc2',
                                 pwd='pwd2')
    wc2ex.checkout()

    # first sync
    # overwrite wc2
    print('merge test 0')
    if reverse:
        sync = syncsvn.SvnSync(PATH_SYNC2,
                               PATH_SYNC1,
                               PATH_JSON,
                               accleft='acc2',
                               pwdleft='pwd2',
                               accright='acc1',
                               pwdright='pwd1',
                               accjson='acc1',
                               pwdjson='pwd1')
        sync.json['MergeUseLeft'] = 1
        sync.json['OverwriteUsePathRight'] = 1
        sync.json['OverwriteUsePathLeft'] = 0
    else:
        sync = syncsvn.SvnSync(PATH_SYNC1,
                               PATH_SYNC2,
                               PATH_JSON,
                               accleft='acc1',
                               pwdleft='pwd1',
                               accright='acc2',
                               pwdright='pwd2',
                               accjson='acc1',
                               pwdjson='pwd1')
        sync.json['MergeUseRight'] = 1
    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # conflict 1, modify same file
    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text01.txt'), 'append left')
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text03.txt'), 'append left')
    remove_file(os.path.join(PATH_SYNC1_EX, 'sub02/bin02.a'))
    create_file(os.path.join(PATH_SYNC1_EX, 'sub02/bin02.a'), 'wtf\n' * 100)
    wc1ex.propset(os.path.join(PATH_SYNC1_EX, 'sub00'), 'svn:ignore',
                  'ignore001')
    # remove_path(os.path.join(PATH_SYNC1_EX, '中文目录03'))
    wc1ex.full_modify()
    wc1ex.commit('modify')
    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text01.txt'), 'append left')
    wc1ex.full_modify()
    wc1ex.commit('左侧中文log')
    wc2ex.update()
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text02.txt'),
                'append right')
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text03.txt'),
                'append right')
    remove_file(os.path.join(PATH_SYNC2_EX, 'sub02/bin02.a'))
    create_file(os.path.join(PATH_SYNC2_EX, 'sub02/bin02.a'), 'ftw\n' * 500)
    # append_file(os.path.join(PATH_SYNC2_EX, '中文目录03/bin03.a'), 'append right')
    wc2ex.propset(os.path.join(PATH_SYNC2_EX, 'sub00'), 'svn:ignore',
                  'ignore002')
    wc2ex.full_modify()
    wc2ex.commit('extra modify')
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text02.txt'),
                'append right')
    wc2ex.full_modify()
    wc2ex.commit('右侧中文log')

    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # tree conflict
    wc1ex.update()
    remove_path(os.path.join(PATH_SYNC1_EX, '中文目录03'))
    wc1ex.full_modify()
    wc1ex.commit('modify')
    wc2ex.update()
    append_file(os.path.join(PATH_SYNC2_EX, '中文目录03/bin03.a'), 'append right')
    wc2ex.full_modify()
    print(wc2ex.commit('extra modify'))

    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    sync.SanBanFu()
Esempio n. 5
0
def test_merge(reverse=False):
    test_repocreate()
    wc1 = pysvn.SvnWorkingCopy(PATH_WC1, URL_REPO1, acc='acc1', pwd='pwd1')
    wc1.checkout()
    wc2 = pysvn.SvnWorkingCopy(PATH_WC2, URL_REPO2, acc='acc2', pwd='pwd2')
    wc2.checkout()
    pysvn.setglobal_accpwd("gacc", 'gpwd')
    # add something to wc1
    create_path(PATH_SYNC1)
    create_file(os.path.join(PATH_SYNC1, 'text01.txt'), 'text01')
    create_path(os.path.join(PATH_SYNC1, 'sub00'))
    create_path(os.path.join(PATH_SYNC1, 'sub01'))
    create_file(os.path.join(PATH_SYNC1, 'sub01/text01.txt'), 'text01')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text03.txt'), 'text03')
    create_path(os.path.join(PATH_SYNC1, 'sub02'))
    create_file(os.path.join(PATH_SYNC1, 'sub02/bin02.a'), 'bin02')
    create_path(os.path.join(PATH_SYNC1, '中文目录03'))
    create_file(os.path.join(PATH_SYNC1, '中文目录03/bin03.a'), 'bin03')
    wc1.full_modify()
    wc1.commit('init')
    wc1ex = pysvn.SvnWorkingCopy(PATH_WC1_EX, URL_REPO1)
    wc1ex.checkout()
    # add something to wc2
    create_path(PATH_SYNC2)
    create_file(os.path.join(PATH_SYNC2, 'text01.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'text02.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub000'))
    create_path(os.path.join(PATH_SYNC2, 'sub01'))
    create_file(os.path.join(PATH_SYNC2, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'sub01/text03.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub03'))
    create_file(os.path.join(PATH_SYNC2, 'sub03/bin03.a'), 'bin03')
    wc2.full_modify()
    wc2.commit('init')
    wc2ex = pysvn.SvnWorkingCopy(PATH_WC2_EX, URL_REPO2)
    wc2ex.checkout()

    # first sync
    # overwrite wc2
    print('merge test 0')
    if reverse:
        sync = syncsvn.SvnSync(PATH_SYNC2, PATH_SYNC1, PATH_JSON)
    else:
        sync = syncsvn.SvnSync(PATH_SYNC1, PATH_SYNC2, PATH_JSON)

    sync.Refresh()
    # modify on the other way
    create_file(os.path.join(PATH_SYNC1_EX, '不存在文件.txt'), '不存在.txt')
    wc1ex.full_modify()
    wc1ex.commit('extra add')
    create_file(os.path.join(PATH_SYNC2_EX, '额外文件.txt'), '额外文件.txt')
    wc2ex.full_modify()
    wc2ex.commit('extra modify')
    # go on sync
    if sync.CheckSync():
        sync.TrySync()
    # sync with merge
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)
    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # sync with merge
    print('merge test 1')
    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text03.txt'),
                'append other')
    create_file(os.path.join(PATH_SYNC1_EX, 'sub01/test04.txt'), 'text04')
    remove_file(os.path.join(PATH_SYNC1_EX, 'sub01/text02.txt'))
    wc1ex.full_modify()
    wc1ex.commit('extra add')
    # sync
    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # sync with merge, commit fail
    print('merge test 2')
    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text03.txt'), 'append left')
    wc1ex.full_modify()
    wc1ex.commit('modify')
    sync.Refresh()
    wc2ex.update()
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text03.txt'),
                'append right', True)
    wc2ex.full_modify()
    wc2ex.commit('extra modify')
    # sync
    if sync.CheckSync():
        sync.TrySync()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)
    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # sync with merge, conflict
    print('merge test 3')
    wc1ex.update()
    append_file(os.path.join(PATH_SYNC1_EX, 'sub01/text03.txt'),
                'append left again')
    wc1ex.full_modify()
    wc1ex.commit('modify')
    sync.Refresh()
    wc2ex.update()
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text03.txt'),
                'append right again')
    wc2ex.full_modify()
    wc2ex.commit('extra modify')
    # sync
    if sync.CheckSync():
        sync.TrySync()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)
    sync.SanBanFu()
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)

    # Loop test
    sync.Loop(10)
Esempio n. 6
0
def test_overwrite(right_to_left=False):
    test_repocreate()
    pysvn.setglobal_accpwd("gacc", 'gpwd')
    wc1 = pysvn.SvnWorkingCopy(PATH_WC1, URL_REPO1)
    wc1.checkout()
    wc2 = pysvn.SvnWorkingCopy(PATH_WC2, URL_REPO2, acc="acc2", pwd="pwd2")
    wc2.checkout()
    # add something to wc1
    create_path(PATH_SYNC1)
    create_file(os.path.join(PATH_SYNC1, 'text01.txt'), 'text01')
    create_path(os.path.join(PATH_SYNC1, 'sub00'))
    create_path(os.path.join(PATH_SYNC1, 'sub01'))
    create_file(os.path.join(PATH_SYNC1, 'sub01/text01   .txt'), 'text01')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC1, 'sub01/text03.txt'), 'text03')
    create_path(os.path.join(PATH_SYNC1, 'sub02'))
    create_file(os.path.join(PATH_SYNC1, 'sub02/bin02.a'), 'bin02')
    create_path(os.path.join(PATH_SYNC1, '中文目录03'))
    create_file(os.path.join(PATH_SYNC1, '中文目录03/bin03.a'), 'bin03')
    wc1.full_modify()
    wc1.commit('init')
    wc1ex = pysvn.SvnWorkingCopy(PATH_WC1_EX, URL_REPO1)
    wc1ex.checkout()
    if right_to_left:
        jsoncontent = {}
        jsoncontent.update(syncsvn.DEFAULT_JSON)
        jsoncontent['OverwriteUsePathLeft'] = 0
        jsoncontent['OverwriteUsePathRight'] = 1
        with open(PATH_JSON, 'w') as f:
            json.dump(jsoncontent, f)
    # add something to wc2
    create_path(PATH_SYNC2)
    create_file(os.path.join(PATH_SYNC2, 'text01.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'text02.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub000'))
    create_path(os.path.join(PATH_SYNC2, 'sub01'))
    create_file(os.path.join(PATH_SYNC2, 'sub01/text02.txt'), 'text02')
    create_file(os.path.join(PATH_SYNC2, 'sub01/text03.txt'), 'text02')
    create_path(os.path.join(PATH_SYNC2, 'sub03'))
    create_file(os.path.join(PATH_SYNC2, 'sub03/bin03.a'), 'bin03')
    wc2.full_modify()
    wc2.commit('init')
    wc2ex = pysvn.SvnWorkingCopy(PATH_WC2_EX, URL_REPO2)
    wc2ex.checkout()
    # overwrite wc2
    sync = syncsvn.SvnSync(PATH_SYNC1, PATH_SYNC2, PATH_JSON)
    sync.Refresh()
    # modify on the other way
    create_file(os.path.join(PATH_SYNC1_EX, '不存在文件.txt'), '不存在.txt')
    wc1ex.full_modify()
    wc1ex.commit('extra add')
    create_file(os.path.join(PATH_SYNC2_EX, '额外文件.txt'), '额外文件.txt')
    append_file(os.path.join(PATH_SYNC2_EX, 'sub01/text03.txt'),
                'something extra')
    wc2ex.full_modify()
    wc2ex.commit('extra modify')
    # go on sync
    if sync.CheckSync():
        sync.TrySync()
    # 测试结果
    pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)
    sync.Refresh()
    if sync.CheckSync():
        sync.TrySync()
    res, _, _, _ = pathcmp.compare_path(PATH_SYNC1, PATH_SYNC2)
    # loop test
    sync.Loop(10)
    return res