Пример #1
0
def cmd_add(args):
    opts , args = getopt.getopt(args, 'a', ["all"])
    if not (args or opts):
        print("""Nothing specified, nothing added.
Maybe you wanted to say 'eni add .'?""")
    add_all = False
    for options in opts:
        if options[0] in ('-a','--all'):
            add_all = True
        else:
            print('Unrecognized Option {}'.format(options[0]))
            print('Please see help for directions on how to use.')
            sys.exit(0)
    if '.' in args:
        add_all = True
    if add_all:
        all_files = get_all_files(repo_dir)
        for file in all_files:
            eni_write_hash_file(file)
            eni_update_index(file)
    else:
        cwd = os.getcwd()
        abs_path_args = [os.path.join(cwd, x) for x in args]
        for name, abs_name in zip(args,abs_path_args):
            if not os.path.exists(abs_name):
                print("fatal: pathspec '{}' did not match any files".format(name))
            if os.path.isdir(abs_name):
                all_files = get_all_files(abs_name)
                for file in all_files:
                    eni_write_hash_file(file)
                    eni_update_index(file)
            else:
                eni_write_hash_file(abs_name)
                eni_update_index(abs_name)
Пример #2
0
def eni_changed_files():
    eni_dir = get_eni_dir()
    repo_dir = str(Path(eni_dir).parent)
    repo_dir = os.path.abspath(repo_dir)
    file_list = get_all_files(repo_dir)
    file_list = map(lambda x: os.path.abspath(x), file_list)
    file_list = map(lambda x: re.sub(repo_dir+r'/?', '', x), file_list)
    index_object = eni_read_index()
    modified_files = []
    added_files = []
    for entry in index_object:
        added_files.append(entry[1])
    cwd = os.getcwd()
    os.chdir(repo_dir)
    for entry in file_list:
        sha1_file = eni_hash_file(entry)
        should_be_path = os.path.join(eni_dir,'objects',sha1_file[:2], sha1_file[2:])
        if not os.path.exists(should_be_path):
            modified_files.append(entry)
    # TODO : Add provision for untracked files
    return modified_files, added_files , []