# [RFD] subtree status - comparing subtree with a remote

1 messages from 2013-02-23 to 2013-02-23. Participants: Paul Campbell.
Thread: https://gitlist.dev/t/32982

## Paul Campbell, 2013-02-23 00:19

Subject: [RFD] subtree status - comparing subtree with a remote
Message-ID: <CALeLG_mF2Fucf=A2Dzn_KFgim8Z3vFpdWR84FYpu5gqKv=S64g@mail.gmail.com>
URL: https://gitlist.dev/e/CALeLG_mF2Fucf%3DA2Dzn_KFgim8Z3vFpdWR84FYpu5gqKv%3DS64g%40mail.gmail.com

```
Hi,

I'm looking at adding a "git subtree status" command that will tell if
a subtree is up-to-date, ahead of, behind, divergant with or unrelated
to a remote repo.

I just wanted to check that I'm working this out correctly before
writing the code.

1) perform a synthetic subtree split

  mine=$(git subtree split --prefix=subtree/path)

This outputs the SHA1 for this subtree in isolation to the superproject.

2) fetch latest branch HEAD from remote repository we're comparing with

  git fetch $repo $branch
  theirs=$(git rev-parse FETCH_HEAD)

3) Find common ancestor

  base=$(git merge-base $mine $theirs)

Where:

* $base == $mine && $base == $theirs : up-to-date

* $base == $mine && $base != $theirs : behind remote - can pull

* $base != $mine && $base == $theirs : ahead of remote - can push

* $base != $mine && $base != $theirs : divergent

* $base == null : no common ancestor - wrong repo?

Comments?

-- 
Paul [W] Campbell

```
