예제 #1
0
def cmd_rev_parse(args):
    if args.type:
        fmt = args.type.encode()

    repo = rp.repo_find()

    print(object.object_find(repo, args.name, args.type, follow=True))
예제 #2
0
def cmd_ls_tree(args):
    repo = rp.repo_find()
    obj = object.object_read(
        repo, object.object_find(repo, args.object, fmt=b'tree'))
    for item in obj.items:
        print("{0} {1} {2}\t{3}".format(
            "0" * (6 - len(item.mode)) + item.mode.decode("ascii"),
            object.object_read(repo, item.sha).fmt.decode("ascii"), item.sha,
            item.path.decode("ascii")))
예제 #3
0
def cmd_tag(args):
    repo = rp.repo_find()

    if args.name:
        tag_create(args.name,
                   args.object,
                   type="object" if args.create_tag_object else "ref")
    else:
        refs = ref_list(repo)
        show_ref(repo, refs["tags"], with_hash=False)
예제 #4
0
def cmd_ls_tree(args):
    repo = repo_find()
    obj = object_read(repo, object_find(repo, args.object, fmt=b"tree"))

    for item in obj.items:
        print("{0} {1} {2}\t{3}".format(
            "0" * (6 - len(item.mode)) + item.mode.decode("ascii"),
            # Git's ls-tree displays the type
            # of the object pointed to.  We can do that too :)
            object_read(repo, item.sha).fmt.decode("ascii"),
            item.sha,
            item.path.decode("ascii"),
        ))
예제 #5
0
def cmd_tag(args):
    repo = repo_find()

    if args.create_tag_object:
        tag_create(
            repo,
            args.name,
            args.object,
            create_tag_object=True,
        )
    elif args.name:
        tag_create(repo, args.name, args.object, create_tag_object=False)
    else:
        refs = ref_list(repo)
        show_ref(repo, refs["tags"], with_hash=False)
예제 #6
0
def cmd_checkout(args):
    repo = rp.repo_find()
    obj = object.object_read(repo, object.object_find(repo, args.commit))

    # If the object is a commit, grab its tree
    if obj.fmt == b'commit':
        obj = object.object_read(repo, obj.kvlm[b'tree'].decode("ascii"))

    # Verify that path is an empty directory
    if os.path.exists(args.path):
        if not os.path.isdir(args.path):
            raise Exception("Not a directory {0}!".format(args.path))
        if os.listdir(args.path):
            raise Exception("Not empty {0}!".format(args.path))
    else:
        os.makedirs(args.path)

    tree_checkout(repo, obj, os.path.realpath(args.path).encode())
예제 #7
0
def cmd_cat_file(args):
    repo = rp.repo_find()
    cat_file(repo, args.object, fmt=args.type.encode())
예제 #8
0
def cmd_show_ref(args):
    repo = rp.repo_find()
    refs = ref_list(repo)
    show_ref(repo, refs, prefix="refs")
예제 #9
0
def cmd_log(args):
    repo = rp.repo_find()
    print("digraph wyaglog{")
    log_graphviz(repo, object.object_find(repo, args.commit), set())
    print("}")
예제 #10
0
def cmd_cat_file(args):
    repo = repo_find()
    cat_file(repo, args.object)