{"thread":{"id":"32982","subject":"[RFD] subtree status - comparing subtree with a remote","startedAt":"2013-02-23T00:19:08Z","lastAt":"2013-02-23T00:19:08Z","messageCount":1,"participants":["Paul Campbell"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"210078","messageId":"CALeLG_mF2Fucf=A2Dzn_KFgim8Z3vFpdWR84FYpu5gqKv=S64g@mail.gmail.com","threadId":"32982","inReplyTo":null,"subject":"[RFD] subtree status - comparing subtree with a remote","fromName":"Paul Campbell","fromEmail":"pcampbell@kemitix.net","sentAt":"2013-02-23T00:19:08Z","receivedAt":"2013-02-23T00:19:08Z","isPatch":false,"sender":{"key":"pcampbell@kemitix.net","avatar":"https://gravatar.com/avatar/57584e05501b694929004e43fcd7308f4ad64df2eb0474cd8c7e5f93662bb0f1?d=mp&s=160"},"body":"Hi,\n\nI'm looking at adding a \"git subtree status\" command that will tell if\na subtree is up-to-date, ahead of, behind, divergant with or unrelated\nto a remote repo.\n\nI just wanted to check that I'm working this out correctly before\nwriting the code.\n\n1) perform a synthetic subtree split\n\n  mine=$(git subtree split --prefix=subtree/path)\n\nThis outputs the SHA1 for this subtree in isolation to the superproject.\n\n2) fetch latest branch HEAD from remote repository we're comparing with\n\n  git fetch $repo $branch\n  theirs=$(git rev-parse FETCH_HEAD)\n\n3) Find common ancestor\n\n  base=$(git merge-base $mine $theirs)\n\nWhere:\n\n* $base == $mine && $base == $theirs : up-to-date\n\n* $base == $mine && $base != $theirs : behind remote - can pull\n\n* $base != $mine && $base == $theirs : ahead of remote - can push\n\n* $base != $mine && $base != $theirs : divergent\n\n* $base == null : no common ancestor - wrong repo?\n\nComments?\n\n-- \nPaul [W] Campbell\n"}]}