<commit_before>-module(git_util).

-export([clone/2]).

clone(GitCloneUrl, {GitRepoPath, GitRepoUser, GitRepoGroup}) ->
    {ok, TmpFile} = file_util:get_tmp_file(),
    ok = build_script(TmpFile, GitCloneUrl, GitRepoPath),
    % TODO: how best to globally indicate debug vs production
    GitCmd = ["/usr/bin/sudo", "-u", GitRepoUser, "-g", GitRepoGroup, "/bin/sh", TmpFile],
    lager:debug("git cmd: ~p", [GitCmd]),
    RunResult = os:cmd(string:join(GitCmd, " ")),
    lager:debug("git result: ~p", [RunResult]),
    ok = file:delete(TmpFile),
    {ok, RunResult}.

build_script(TmpFile, GitCloneUrl, GitRepoPath) ->
    {ok, GitPath} = application:get_env(autodeploy, git),
    {ok, F} = file:open(TmpFile, [write]),
    ok = file:write(F, "#!/bin/sh\n"),
    ok = file:write(F, "id -a\n"),
    ok = io:format(F, "mkdir -p ~s~n", [GitRepoPath]),
    ok = file:write(F, "set -o errexit\n"),
    ok = io:format(F, "cd ~s~n", [GitRepoPath]),
    ok = file:write(F, "find . -delete\n"),
    ok = io:format(F, "~s clone --verbose --progress ~s > /tmp/clone.out 2>&1~n", [GitPath, GitCloneUrl]),
    ok = file:write(F, "exit $?\n"),
    ok = file:close(F).
<commit_msg>small change to git clone script<commit_after>-module(git_util).

-export([clone/2]).

clone(GitCloneUrl, {GitRepoPath, GitRepoUser, GitRepoGroup}) ->
    {ok, TmpFile} = file_util:get_tmp_file(),
    ok = build_script(TmpFile, GitCloneUrl, GitRepoPath),
    % TODO: how best to globally indicate debug vs production
    GitCmd = ["/usr/bin/sudo", "-u", GitRepoUser, "-g", GitRepoGroup, "/bin/sh", TmpFile],
    lager:debug("git cmd: ~p", [GitCmd]),
    RunResult = os:cmd(string:join(GitCmd, " ")),
    lager:debug("git result: ~p", [RunResult]),
    ok = file:delete(TmpFile),
    {ok, RunResult}.

build_script(TmpFile, GitCloneUrl, GitRepoPath) ->
    {ok, GitPath} = application:get_env(autodeploy, git),
    {ok, F} = file:open(TmpFile, [write]),
    ok = file:write(F, "#!/bin/sh\n"),
    ok = file:write(F, "id -a\n"),
    ok = io:format(F, "mkdir -p ~s~n", [GitRepoPath]),
    ok = file:write(F, "set -o errexit\n"),
    ok = io:format(F, "cd ~s~n", [GitRepoPath]),
    ok = file:write(F, "find . -delete\n"),
    ok = file:write(F, "cd ..\n"),
    ok = io:format(F, "~s clone --verbose --progress ~s > /tmp/clone.out 2>&1~n", [GitPath, GitCloneUrl]),
    ok = file:write(F, "exit $?\n"),
    ok = file:close(F).

{'fraction_non_alphanumeric': 0.2087866108786611, 'fraction_numerical': 0.002510460251046025, 'mean_word_length': 3.8012048192771086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2799614', 'n_tokens_mistral': 954, 'n_tokens_neox': 953, 'n_words': 207}