0

The following command runs as expected in the shell:

git log --since=yesterday.midnight --before=today.midnight --format= --name-status

When translated into the following python code however it fails:

git = subprocess.Popen(['git', 'log', '--since=yesterday.midnight', '--before=today.midnight', '--format= --name-status'], stdout=subprocess.PIPE)

Error:

fatal: invalid --pretty format:  --name-status

The closest answer I can find to this is regarding solving a problem on Windows (I'm on a Mac) here: How to use subprocess when multiple arguments contain spaces?

From the above answer I tried the following variations of quoting but none of them worked:

git = subprocess.Popen(['git', 'log', '--since=yesterday.midnight', '--before=today.midnight', '"--format= --name-status"'], stdout=subprocess.PIPE)
fatal: ambiguous argument '"--format= --name-status"': unknown revision or path not in the working tree.

git = subprocess.Popen(['git', 'log', '--since=yesterday.midnight', '--before=today.midnight', '--format=" --name-status"'], stdout=subprocess.PIPE)
fatal: invalid --pretty format: " --name-status"

git = subprocess.Popen(['git', 'log', '--since=yesterday.midnight', '--before=today.midnight', '--format= "--name-status"'], stdout=subprocess.PIPE)
fatal: invalid --pretty format:  "--name-status"

Using "" instead of "" in the same positions as above resulted in the exact same errors as above.

My underlying need is to generate list of all files added and modified yesterday.

I just learned the subprocess syntax a couple days ago so there may also be a better way to go about this. My script runs the command then calls git.stdout.read().splitlines() to produce a list for follow-on manipulation and partitioning of the results.

Appreciate any help, thanks.

1 Answer 1

1

You're just missing one comma.

git = subprocess.Popen(
    [
        "git",
        "log",
        "--since=yesterday.midnight",
        "--before=today.midnight",
        "--format=",  # <-- this one!
        "--name-status",
    ],
    stdout=subprocess.PIPE,
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Unfortunately even with that verbatim I still get fatal: invalid --pretty format: --name-status when the script runs. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.