threads / discuss / 32982

[RFD] subtree status - comparing subtree with a remote

Subject: [RFD] subtree status - comparing subtree with a remote

## tl;dr

One message between Feb 23, 2013 and Feb 23, 2013.

replies: 0people: 1as markdown or json

Paul Campbell· Feb 23, 2013, 00:19 UTC · lore
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

← back to recent threads