Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the list of files about to be updated by `git pull` without knowing the branch name or what it tracks?

Tags:

git

How do I get the list of files that are about to be updated (or were just updated) by git pull so i can parse them and take appropriate action in a script?

The accepted answer to this similar looking question showed me that I can get a list of commits with

git fetch && git log master..origin/master

but this is no good for me because I need a list of files, and my script cannot assume that the branch is master or that the current branch is tracking origin/master.

Through a little experimentation (and @Jonathan's comment), I have found that

git fetch && git diff master origin/master --name-only

is nearly there, but now I need to find a way to get the current branch and what it's tracking so that I can execute something like this (python):

"git fetch && git diff %s %s --stat" % (this_branch, tracked_branch)

I feel like I'm most of the way there, as now I only really need to know how to get the current branch and what it's tracking, but I've given a wider context in the hope that someone knows a much simpler way of solving this (git incoming --files would be nice ;)

like image 405
meshy Avatar asked Dec 15 '11 15:12

meshy


1 Answers

Assuming you know the name of the remote (in my examples, origin) then you could simply go:

git fetch && git diff --name-only ..origin

templates/shows/showBase.html
templates/shows/showList.html
templates/shows/showListEntry.htm

Or if you wanted to sort into individual commits, you could use whatchanged:

git fetch && git whatchanged --name-only ..origin

commit fcb1b56d564fe85615ecd6befcd82f6fda5699ae
Author: Grambo <email@email>
Date:   Mon Dec 12 23:36:38 2011 +0000

    Hooked "I've Seen This" button up to "Review Show" dialog

templates/shows/showBase.html
templates/shows/showList.html
templates/shows/showListEntry.htm

commit xasdasdsada......
like image 90
obmarg Avatar answered Sep 18 '22 13:09

obmarg