1

I use the git status --porcelain command to check the status of a local repository in Deno, it parses this command and returns an array with modified / unchanged / untracked files. Which works great! But I also want to do the same for git pull, I'd like to return something, an boolean, string or maybe Enum, I really don't know yet.

The problem is I can't get a clean, simple response that is script friendly and can be parsed by Deno consistently (which is the exact point of the --porcelain option if I understood it correctly). Which is why I am asking: is there a --porcelain like option for git pull?

Schotsl
  • 187
  • 1
  • 8
  • 29

2 Answers2

1

As answered by anpel, git pull behind the scenes actually does a fetch and a merge.

To perform a "fast-forward or abort" pull, you can perform the fetch yourself, and then merge with the --ff-only option:

git remote update
git merge --ff-only origin/master

If you work on multiple branches, you can refer to this nice answer on programmatically determining the upstream (tracking) branch and replace origin/master with it.

iBug
  • 35,554
  • 7
  • 89
  • 134
  • I see, I didn't know this! But then my question becomes: is there a `--porcelain` like option for `git merge`? ;) – Schotsl Dec 11 '20 at 18:16
  • @Schotsl The `--ff-only` option is exactly what you're looking for: The operation succeeds only if it can be fast-forwarded. – iBug Dec 11 '20 at 20:25
  • I meant if the output could be simplified to be parsed for a script, since `--porcelain` has the guarantee to remain the same to ensure it can be parsed by a script. – Schotsl Dec 16 '20 at 14:36
  • @Schotsl In that case, using `git merge --ff-only`, you don't rely on the output - you check the exit code where 0 means success. – iBug Dec 16 '20 at 14:42
0

git status does not cause any changes to your repository and does not require any user input or actions to be completed.

git pull is a very different scenario. Internally, git pull runs both git fetch and git merge (check here for more).

Essentially, this means that it might create subsequent commits or merge conflicts, so it would require user input to be completed, so it cannot be done, unless you can absolutely guarantee that all your future commits will be able to fast forward.

anpel
  • 931
  • 6
  • 16