Пример #1
0
def t18():
    pretty = '%s t18' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t18')

    src = 'git://review.sonyericsson.net/semctools/ave/vcsjob.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master', depth='2')
        cmd = [
            'git',
            '--git-dir=%s/.git' % dst, '--work-tree=' + dst, 'rev-list',
            'HEAD', '--count'
        ]
        (s, o, e) = ave.cmd.run(cmd, timeout=100, debug=False)
        if int(o) != 2:
            print(
                'FAIL %s: git clone parameter --depth is ignored in clones.' %
                pretty)
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return False
Пример #2
0
def t5():
    pretty = '%s t5' % __file__
    print(pretty)

    exc = None
    try:
        vcsjob.fetch('/', 'nonsense', 'nonsense')
    except Exception, e:
        exc = e
Пример #3
0
def t6():
    pretty = '%s t6' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t6')

    # create a git tree in a temp directory to use for this test
    src = make_vcsjob_tree(w)

    exc = None
    try:
        vcsjob.fetch(src, 'ssh://host', 'bleh')
    except Exception, e:
        exc = e
Пример #4
0
def t7():
    pretty = '%s t7' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t7')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Пример #5
0
def t20():
    pretty = '%s t20' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t20')

    src = 'git://review.sonyericsson.net/platform/prebuilts/misc.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'oss/tools_r22.2')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        w.delete()
        return False
Пример #6
0
def t13():
    pretty = '%s t13' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t13')

    src = make_vcsjob_tree(w)

    # pull the tree into a temporary directory, check that the current branch
    # is "master".
    dst = w.make_tempdir()

    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: could not fetch master: %s' % (pretty, str(e)))
        return
Пример #7
0
def t12():
    pretty = '%s t12' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t12')

    src = make_vcsjob_tree(w)

    # set up destination in a temporary directory that contains some dirt
    dst = w.make_tempdir()
    f = open(os.path.join(dst, 'dirt.txt'), 'w')
    f.write('bar')
    f.close()

    exc = None
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        exc = e
Пример #8
0
def t17():
    pretty = '%s t17' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t17')

    # set up the source
    src = make_vcsjob_tree(w)

    # set up an empty destination
    dst = w.make_tempdir()

    # first fetch
    vcsjob.fetch(src, dst, 'master')

    # check contents
    with open(os.path.join(dst, 'foo.txt'), 'r') as f:
        contents = f.read()
        if contents != 'bar':
            print('FAIL %s: wrong original content: %s' % (pretty, contents))
            return False

    # create new commit in source
    with open(os.path.join(src, 'foo.txt'), 'w') as f:
        f.write('barfly')
    ave.git.add(src, '.')
    ave.git.commit(src, 'Third commit')

    # second fetch
    vcsjob.fetch(src, dst, 'master')

    # check contents again
    with open(os.path.join(dst, 'foo.txt'), 'r') as f:
        contents = f.read()
        if contents != 'barfly':
            print('FAIL %s: wrong delta content: %s' % (pretty, contents))
            return False

    return True
Пример #9
0
def t19():
    pretty = '%s t19' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t19')

    src = 'git://review.sonyericsson.net/platform/prebuilts/misc.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'oss/tools_r22.2', timeout=1)
        print('FAIL %s: it should be timeout') % pretty
        w.delete()
        return False
    except Exception, e:
        if 'command timed out' == str(e):
            w.delete()
            return True
        else:
            print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
            w.delete()
            return False
Пример #10
0
def t16():
    pretty = '%s t16' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t16')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    exc = None
    try:
        result = vcsjob.fetch(src, dst, 'no_such_branch')
    except Exception, e:
        exc = e
Пример #11
0
def t14():
    pretty = '%s t14' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t14')

    src = make_vcsjob_tree(w)

    # pull "master"
    dst = w.make_tempdir()

    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: first fetch failed: %s' % (pretty, str(e)))
        return
Пример #12
0
def t9():
    pretty = '%s t9' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t9')

    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # pull the tree into a temporary directory, check that the current branch
    # is "master".
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Пример #13
0
def t15():
    pretty = '%s t15' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t15')

    src = make_vcsjob_tree(w)
    ids = ave.git.rev_list(src)

    # pull "master"
    dst = w.make_tempdir()

    try:
        result = vcsjob.fetch(src, dst, ids[1])
    except Exception, e:
        print('FAIL %s: first fetch failed: %s' % (pretty, str(e)))
        return
Пример #14
0
def t8():
    pretty = '%s t8' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t8')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # repeatedly fetch the source into the destination
    result = vcsjob.OK
    for i in range(5):
        try:
            result += vcsjob.fetch(src, dst, 'master')
        except Exception, e:
            print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
            return
Пример #15
0
def t10():
    pretty = '%s t10' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t10')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)

    # "create" a non-existant destination directory by removing a temporary dir
    dst = w.make_tempdir()
    shutil.rmtree(dst)

    # fetch the source into the destination
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Пример #16
0
def t11():
    pretty = '%s t11' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t11')

    src = make_vcsjob_tree(w)

    # create a non-directory destination
    dst = os.path.join(w.make_tempdir(), 'some_file')
    with open(dst, 'w') as f:
        f.write('anything')
        f.close()

    # fetch the source into the destination
    exc = None
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        exc = e
Пример #17
0
    # create another commit in the source
    f = open(os.path.join(src, 'foo.txt'), 'w+')
    f.write('')
    f.close()
    ave.git.add(src, '.')
    ave.git.commit(src, 'Second commit')

    # introduce some dirt in the destination
    f = open(os.path.join(dst, 'dirt'), 'w')
    f.write('some dirt for `git status` to pick up')
    f.close()

    # fetch again into the same directory, expect failure
    exc = None
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        exc = e

    if not exc:
        print('FAIL %s: fetch did not fail on dirty destination' % pretty)
        return

    # check the error message
    if 'can\'t pull into a dirty tree' not in str(exc):
        print('FAIL%s: wrong error message: %s' % (pretty, str(exc)))
        return

    w.delete()