{"thread":{"id":"19415","subject":"How to check repository/working tree status from a script","startedAt":"2009-05-19T14:35:37Z","lastAt":"2009-05-23T20:39:26Z","messageCount":15,"participants":["Marc Haber","Tony Finch","Linus Torvalds","Santi Béjar","Johannes Sixt","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114274","messageId":"20090519143537.GA23505@torres.zugschlus.de","threadId":"19415","inReplyTo":null,"subject":"How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-19T14:35:37Z","receivedAt":"2009-05-19T14:35:37Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"Hi,\n\nI am kind of new to git, and my thinking is still somewhat\nsvn-centric. Please keep this in mind just in case that I have\nmisunderstood some of git's concepts.\n\nI would like to check in a script whether there (a) are uncommitted\nchanges (as in \"working tree differs from local repository\") and/or\nwhether there (b) are unpulled changes in the \"remote origin\"\nrepository.\n\nI have to admit that I didn't bother about (b) yet, but for (a) there\nseems no possibility other than to parse git status' output since it\nseems to always return exit code 1:\n\n$ GIT_PAGER=cat git status; echo $?\n# On branch master\nnothing to commit (working directory clean)\n1\n$ touch keks\n$ GIT_PAGER=cat git status; echo $?\n# On branch master\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       bla\nnothing added to commit but untracked files present (use \"git add\" to\ntrack)\n1\n$\n\nAm I missing something here? Is there documentation about the exit\ncodes of the different git subcommands or probably a complete solution\nfor my two endeavours?\n\nAny hints will be appreciated.\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114275","messageId":"alpine.LSU.2.00.0905191630120.23478@hermes-2.csi.cam.ac.uk","threadId":"19415","inReplyTo":"20090519143537.GA23505@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2009-05-19T15:34:47Z","receivedAt":"2009-05-19T15:34:47Z","isPatch":false,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"On Tue, 19 May 2009, Marc Haber wrote:\n\nHi Marc.\n\n> I would like to check in a script whether there (a) are uncommitted\n> changes (as in \"working tree differs from local repository\")\n\n# check working tree is not different from the index\ngit diff --quiet\n# check that the index is not different from the head\ngit diff --quiet --cached\n\n> and/or whether there (b) are unpulled changes in the \"remote origin\"\n> repository.\n\nDunno, sorry.\n\nTony.\n-- \nf.anthony.n.finch  <dot@dotat.at>  http://dotat.at/\nGERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.\nMODERATE OR GOOD.\n"},{"id":"114276","messageId":"20090519160031.GB23505@torres.zugschlus.de","threadId":"19415","inReplyTo":"alpine.LSU.2.00.0905191630120.23478@hermes-2.csi.cam.ac.uk","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-19T16:00:31Z","receivedAt":"2009-05-19T16:00:31Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"Hi Tony,\n\nOn Tue, May 19, 2009 at 04:34:47PM +0100, Tony Finch wrote:\n> On Tue, 19 May 2009, Marc Haber wrote:\n> > I would like to check in a script whether there (a) are uncommitted\n> > changes (as in \"working tree differs from local repository\")\n> \n> # check working tree is not different from the index\n> git diff --quiet\n> # check that the index is not different from the head\n> git diff --quiet --cached\n\n$ git diff --quiet; echo $?\n0\n$ git diff --quiet --cached; echo $?\n0\n$ touch keks\n$ git diff --quiet; echo $?\n0\n$ git diff --quiet --cached; echo $?\n0\n$\n\nAm I missing something?\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114279","messageId":"alpine.LSU.2.00.0905191710430.23478@hermes-2.csi.cam.ac.uk","threadId":"19415","inReplyTo":"20090519160031.GB23505@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Tony Finch","fromEmail":"dot@dotat.at","sentAt":"2009-05-19T16:16:36Z","receivedAt":"2009-05-19T16:16:36Z","isPatch":false,"sender":{"key":"dot@dotat.at","avatar":"https://avatars.githubusercontent.com/u/68429?v=4"},"body":"On Tue, 19 May 2009, Marc Haber wrote:\n>\n> Am I missing something?\n\ngit-diff won't tell you about untracked files.\n\nUse git ls-files --others --exclude-standard\n\nTony.\n-- \nf.anthony.n.finch  <dot@dotat.at>  http://dotat.at/\nGERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.\nMODERATE OR GOOD.\n"},{"id":"114280","messageId":"alpine.LFD.2.01.0905190915050.3301@localhost.localdomain","threadId":"19415","inReplyTo":"20090519160031.GB23505@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-05-19T16:18:12Z","receivedAt":"2009-05-19T16:18:12Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 19 May 2009, Marc Haber wrote:\n> \n> On Tue, May 19, 2009 at 04:34:47PM +0100, Tony Finch wrote:\n> > On Tue, 19 May 2009, Marc Haber wrote:\n> > > I would like to check in a script whether there (a) are uncommitted\n> > > changes (as in \"working tree differs from local repository\")\n> > \n> > # check working tree is not different from the index\n> > git diff --quiet\n> > # check that the index is not different from the head\n> > git diff --quiet --cached\n> \n> $ git diff --quiet; echo $?\n> 0\n> $ git diff --quiet --cached; echo $?\n> 0\n> $ touch keks\n> $ git diff --quiet; echo $?\n> 0\n> $ git diff --quiet --cached; echo $?\n> 0\n> $\n> \n> Am I missing something?\n\nIf \"keks\" is already something you know about, then 'touch' wouldn't have \nchanged it, so diff won't show it.\n\nAnd if what you want to know about is whether there are _new_ files you \nmight want to check, then you need a third check: 'git ls-files'. You \nwon't see it in the error code, but you can do\n\n\tothers=$(git ls-files -o --exclude-standard)\n\nand then check it 'others' is empty or not.\n\n\t\t\tLinus\n"},{"id":"114282","messageId":"alpine.LFD.2.01.0905190920051.3301@localhost.localdomain","threadId":"19415","inReplyTo":"alpine.LFD.2.01.0905190915050.3301@localhost.localdomain","subject":"Re: How to check repository/working tree status from a script","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-05-19T16:29:08Z","receivedAt":"2009-05-19T16:29:08Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 19 May 2009, Linus Torvalds wrote:\n> \n> And if what you want to know about is whether there are _new_ files you \n> might want to check, then you need a third check: 'git ls-files'. You \n> won't see it in the error code, but you can do\n> \n> \tothers=$(git ls-files -o --exclude-standard)\n> \n> and then check it 'others' is empty or not.\n\nActually, you can use 'git ls-files' to also list files that are changed \nwrt the index, so then you can drop the 'git diff' thing.\n\nIOW, something like this:\n\n\t# any staged changes (ready to commit)\n\tgit diff --quiet --staged || echo Staged changes\n\n\t# any changes wrt the index (not staged)\n\tothers=$(git ls-files --exclude-standard -o -d -m -u)\n\t[ -z \"$others\" ] || echo \"Other changes\"\n\nshould do it.\n\nIf you want more specificity wrt the \"Other changes\", you can add the \"-t\" \nflag to git ls-files and parse the output to see whether the listed files \nwere just unknown (ie new files): '?', changed: 'C', removed: 'R' or need \nto be merged: 'M'\n\nOf course, 'git diff [--staged]' is needed if you actually want to know \nsome \"deeper\" patterns about _how_ things were changed. IOW, if you want \nto know about renames/copies, you need to use 'git diff -M/C' to get that \nkind of information.\n\n\t\t\tLinus\n"},{"id":"114337","messageId":"20090520111028.GA15453@torres.zugschlus.de","threadId":"19415","inReplyTo":"alpine.LFD.2.01.0905190915050.3301@localhost.localdomain","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-20T11:10:28Z","receivedAt":"2009-05-20T11:10:28Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"On Tue, May 19, 2009 at 09:18:12AM -0700, Linus Torvalds wrote:\n> On Tue, 19 May 2009, Marc Haber wrote:\n> > On Tue, May 19, 2009 at 04:34:47PM +0100, Tony Finch wrote:\n> > > On Tue, 19 May 2009, Marc Haber wrote:\n> > > > I would like to check in a script whether there (a) are uncommitted\n> > > > changes (as in \"working tree differs from local repository\")\n> > > \n> > > # check working tree is not different from the index\n> > > git diff --quiet\n> > > # check that the index is not different from the head\n> > > git diff --quiet --cached\n> > \n> > $ git diff --quiet; echo $?\n> > 0\n> > $ git diff --quiet --cached; echo $?\n> > 0\n> > $ touch keks\n> > $ git diff --quiet; echo $?\n> > 0\n> > $ git diff --quiet --cached; echo $?\n> > 0\n> > $\n> > \n> > Am I missing something?\n> \n> If \"keks\" is already something you know about, then 'touch' wouldn't have \n> changed it, so diff won't show it.\n\nkeks didn't exist previously, so the touch generated a new empty 0 byte\nfile.\n\n> And if what you want to know about is whether there are _new_ files you \n> might want to check, then you need a third check: 'git ls-files'. You \n> won't see it in the error code, but you can do\n> \n> \tothers=$(git ls-files -o --exclude-standard)\n> \n> and then check it 'others' is empty or not.\n\nSo parsing the output is both the canonical and only way to do so\nsince there is no meaningful exit code? Can I assume that the\nformatting of git output is not subject to change?\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114338","messageId":"adf1fd3d0905200419s33d5c73ahba240b354aca87a3@mail.gmail.com","threadId":"19415","inReplyTo":"20090520111028.GA15453@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-05-20T11:19:05Z","receivedAt":"2009-05-20T11:19:05Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/5/20 Marc Haber <mh+git@zugschlus.de>:\n> On Tue, May 19, 2009 at 09:18:12AM -0700, Linus Torvalds wrote:\n>> On Tue, 19 May 2009, Marc Haber wrote:\n>> > On Tue, May 19, 2009 at 04:34:47PM +0100, Tony Finch wrote:\n>> > > On Tue, 19 May 2009, Marc Haber wrote:\n>> > > > I would like to check in a script whether there (a) are uncommitted\n>> > > > changes (as in \"working tree differs from local repository\")\n>> > >\n>> > > # check working tree is not different from the index\n>> > > git diff --quiet\n>> > > # check that the index is not different from the head\n>> > > git diff --quiet --cached\n>> >\n>> > $ git diff --quiet; echo $?\n>> > 0\n>> > $ git diff --quiet --cached; echo $?\n>> > 0\n>> > $ touch keks\n>> > $ git diff --quiet; echo $?\n>> > 0\n>> > $ git diff --quiet --cached; echo $?\n>> > 0\n>> > $\n>> >\n>> > Am I missing something?\n>>\n>> If \"keks\" is already something you know about, then 'touch' wouldn't have\n>> changed it, so diff won't show it.\n>\n> keks didn't exist previously, so the touch generated a new empty 0 byte\n> file.\n\nAnd 'git diff' alone only cares about files it knows.\n\n>\n>> And if what you want to know about is whether there are _new_ files you\n>> might want to check, then you need a third check: 'git ls-files'. You\n>> won't see it in the error code, but you can do\n>>\n>>       others=$(git ls-files -o --exclude-standard)\n>>\n>> and then check it 'others' is empty or not.\n>\n> So parsing the output is both the canonical and only way to do so\n> since there is no meaningful exit code? Can I assume that the\n> formatting of git output is not subject to change?\n\nGit output for the plumbing comands do not change, it is designed for\nscript use. OTOH git output for porcelain commands can change. 'git\nls-files' is a plumbing commands, see git's manpage for the complete\nlist.\n\nHTH,\nSanti\n"},{"id":"114339","messageId":"4A13EA4E.9050805@viscovery.net","threadId":"19415","inReplyTo":"20090520111028.GA15453@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-05-20T11:32:30Z","receivedAt":"2009-05-20T11:32:30Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Marc Haber schrieb:\n> On Tue, May 19, 2009 at 09:18:12AM -0700, Linus Torvalds wrote:\n>> And if what you want to know about is whether there are _new_ files you \n>> might want to check, then you need a third check: 'git ls-files'. You \n>> won't see it in the error code, but you can do\n>>\n>> \tothers=$(git ls-files -o --exclude-standard)\n>>\n>> and then check it 'others' is empty or not.\n> \n> So parsing the output is both the canonical and only way to do so\n> since there is no meaningful exit code? Can I assume that the\n> formatting of git output is not subject to change?\n\nSee 'man git':\n\n\"Porcelain\" commands are *not* for use in scripts; their output may\nchange. git diff, git status, git commit, git checkout are in this category.\n\n\"Plumbing\" commands are for use in scripts and their output will not\nchange. git ls-files, git diff-tree, git diff-files are in this category.\n\n-- Hannes\n"},{"id":"114347","messageId":"20090520142742.GB15453@torres.zugschlus.de","threadId":"19415","inReplyTo":"alpine.LFD.2.01.0905190920051.3301@localhost.localdomain","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-20T14:27:42Z","receivedAt":"2009-05-20T14:27:42Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"On Tue, May 19, 2009 at 09:29:08AM -0700, Linus Torvalds wrote:\n> IOW, something like this:\n> \n> \t# any staged changes (ready to commit)\n> \tgit diff --quiet --staged || echo Staged changes\n> \n> \t# any changes wrt the index (not staged)\n> \tothers=$(git ls-files --exclude-standard -o -d -m -u)\n> \t[ -z \"$others\" ] || echo \"Other changes\"\n> \n> should do it.\n\nThis looks good.\n\n> If you want more specificity wrt the \"Other changes\", you can add the \"-t\" \n> flag to git ls-files and parse the output to see whether the listed files \n> were just unknown (ie new files): '?', changed: 'C', removed: 'R' or need \n> to be merged: 'M'\n> \n> Of course, 'git diff [--staged]' is needed if you actually want to know \n> some \"deeper\" patterns about _how_ things were changed. IOW, if you want \n> to know about renames/copies, you need to use 'git diff -M/C' to get that \n> kind of information.\n\nThanks. It's ok to just barf if there are any changes.\n\nBackground info: the data being version controlled is not source, but\nconfiguration for one system which is collaboratively maintained.\nThere is a script which takes the currently checked out working tree,\n\"compiles\" it into the actual configuration and rsyncs/activates the actual\nconfiguration to the (one) target system. I would like to make sure\nthat if one of the admins runs this script, she has (a) pulled  all\nchanges that others may have pushed to the central repository and (b)\nall her local changes are actually committed to her local repository\nand (c) pushed to the central repository.\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n\nBitte beachten Sie, daß dem [m.E. grundgesetzwidrigen] Gesetz zur\nVorratsdatenspeicherung zufolge, seit dem 1. Januar 2008 jeglicher\nelektronische Kontakt (E-Mail, Telefongespräche, SMS, Internet-\nTelefonie, Mobilfunk, Fax) mit mir oder anderen Nutzern verdachts-\nunabhängig für den automatisierten geheimen Zugriff durch Strafver-\nfolgungs- u. Polizeivollzugsbehörden, die Bundesanstalt für Finanz-\ndienstleistungsaufsicht, Zollkriminal- und Zollfahndungsämter,die\nZollverwaltung zur Schwarzarbeitsbekämpfung, Notrufabfragestellen,\nVerfassungsschutzbehörden, den Militärischen Abschirmdienst, Bundes-\nnachrichtendienst sowie 52 Staaten wie beispielsweise Aserbeidschan\noder die USA sechs Monate lang gespeichert wird, einschließlich der\nKommunikation mit Berufsgeheimnisträgern wie Ärzten, Journalisten und\nAnwälten. Mehr Infos zur totalen Protokollierung Ihrer Kommunikations-\ndaten auf www.vorratsdatenspeicherung.de. (leicht verändert übernommen\nkopiert von www.lawblog.de)\n"},{"id":"114348","messageId":"20090520142815.GC15453@torres.zugschlus.de","threadId":"19415","inReplyTo":"alpine.LSU.2.00.0905191710430.23478@hermes-2.csi.cam.ac.uk","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-20T14:28:15Z","receivedAt":"2009-05-20T14:28:15Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"On Tue, May 19, 2009 at 05:16:36PM +0100, Tony Finch wrote:\n> On Tue, 19 May 2009, Marc Haber wrote:\n> > Am I missing something?\n> \n> git-diff won't tell you about untracked files.\n\nUnderstood. Now. Thanks. ;)\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114349","messageId":"20090520142958.GD15453@torres.zugschlus.de","threadId":"19415","inReplyTo":"4A13EA4E.9050805@viscovery.net","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-20T14:29:58Z","receivedAt":"2009-05-20T14:29:58Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"On Wed, May 20, 2009 at 01:32:30PM +0200, Johannes Sixt wrote:\n> See 'man git':\n> \n> \"Porcelain\" commands are *not* for use in scripts; their output may\n> change. git diff, git status, git commit, git checkout are in this category.\n> \n> \"Plumbing\" commands are for use in scripts and their output will not\n> change. git ls-files, git diff-tree, git diff-files are in this category.\n\nMissed that. Sorry. Thanks.\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114414","messageId":"20090521132457.GB5625@torres.zugschlus.de","threadId":"19415","inReplyTo":"20090519143537.GA23505@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-21T13:24:57Z","receivedAt":"2009-05-21T13:24:57Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"Hi,\n\nOn Tue, May 19, 2009 at 04:35:37PM +0200, Marc Haber wrote:\n> I would like to check in a script whether there (a) are uncommitted\n> changes (as in \"working tree differs from local repository\") and/or\n> whether there (b) are unpulled changes in the \"remote origin\"\n> repository.\n\n(a) has been solved, thanks for helping.\n\nI am now looking for a solution for (b). I tried \n\ngit log -n1 --pretty=oneline master..origin/master\n\nbut that seems to always give empty output even if a later issued git\npull will actually pull in changes.\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n"},{"id":"114426","messageId":"20090521153745.GA23463@coredump.intra.peff.net","threadId":"19415","inReplyTo":"20090521132457.GB5625@torres.zugschlus.de","subject":"Re: How to check repository/working tree status from a script","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-21T15:37:45Z","receivedAt":"2009-05-21T15:37:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 21, 2009 at 03:24:57PM +0200, Marc Haber wrote:\n\n> I am now looking for a solution for (b). I tried \n> \n> git log -n1 --pretty=oneline master..origin/master\n> \n> but that seems to always give empty output even if a later issued git\n> pull will actually pull in changes.\n\nTry running \"git fetch\" beforehand, which will actually update\norigin/master with what is on the remote.\n\nAlso, if you are just checking to see whether there is any output, you\ncan use the plumbing \"git rev-list\" instead of \"git log\". So something\nlike:\n\n  git fetch origin || { echo >&2 unable to fetch; exit 1; }\n  test -z \"`git rev-list -1 master..origin/master`\"\n\n-Peff\n"},{"id":"114537","messageId":"20090523203926.GA24004@torres.zugschlus.de","threadId":"19415","inReplyTo":"20090521153745.GA23463@coredump.intra.peff.net","subject":"Re: How to check repository/working tree status from a script","fromName":"Marc Haber","fromEmail":"mh+git@zugschlus.de","sentAt":"2009-05-23T20:39:26Z","receivedAt":"2009-05-23T20:39:26Z","isPatch":false,"sender":{"key":"mh+git@zugschlus.de","avatar":null},"body":"On Thu, May 21, 2009 at 11:37:45AM -0400, Jeff King wrote:\n> On Thu, May 21, 2009 at 03:24:57PM +0200, Marc Haber wrote:\n> > I am now looking for a solution for (b). I tried \n> > \n> > git log -n1 --pretty=oneline master..origin/master\n> > \n> > but that seems to always give empty output even if a later issued git\n> > pull will actually pull in changes.\n> \n> Try running \"git fetch\" beforehand, which will actually update\n> origin/master with what is on the remote.\n\nI slowly begin to grasp how git works. Thanks for enlightening.\n\n> Also, if you are just checking to see whether there is any output, you\n> can use the plumbing \"git rev-list\" instead of \"git log\". So something\n> like:\n> \n>   git fetch origin || { echo >&2 unable to fetch; exit 1; }\n>   test -z \"`git rev-list -1 master..origin/master`\"\n\nif ! git fetch origin; then\n  echo >&2 \"unable to fetch\"\n  exit 1\nfi\nif git rev-list -1 master..origin/master | grep -q . ; then\n  echo >&2 \"unmerged changes on remote repository\"\n  exit 1\nfi\n\nWorks fine. Thanks.\n\nGreetings\nMarc\n\n-- \n-----------------------------------------------------------------------------\nMarc Haber         | \"I don't trust Computers. They | Mailadresse im Header\nMannheim, Germany  |  lose things.\"    Winona Ryder | Fon: *49 621 72739834\nNordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190\n\nBitte beachten Sie, daß dem [m.E. grundgesetzwidrigen] Gesetz zur\nVorratsdatenspeicherung zufolge, seit dem 1. Januar 2008 jeglicher\nelektronische Kontakt (E-Mail, Telefongespräche, SMS, Internet-\nTelefonie, Mobilfunk, Fax) mit mir oder anderen Nutzern verdachts-\nunabhängig für den automatisierten geheimen Zugriff durch Strafver-\nfolgungs- u. Polizeivollzugsbehörden, die Bundesanstalt für Finanz-\ndienstleistungsaufsicht, Zollkriminal- und Zollfahndungsämter,die\nZollverwaltung zur Schwarzarbeitsbekämpfung, Notrufabfragestellen,\nVerfassungsschutzbehörden, den Militärischen Abschirmdienst, Bundes-\nnachrichtendienst sowie 52 Staaten wie beispielsweise Aserbeidschan\noder die USA sechs Monate lang gespeichert wird, einschließlich der\nKommunikation mit Berufsgeheimnisträgern wie Ärzten, Journalisten und\nAnwälten. Mehr Infos zur totalen Protokollierung Ihrer Kommunikations-\ndaten auf www.vorratsdatenspeicherung.de. (leicht verändert übernommen\nkopiert von www.lawblog.de)\n"}]}