Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding ability to track (really, pin) to hashes.

  • Loading branch information...
commit e33ffb21e55f12f730658c8142a851e4300feff7 1 parent 5382720
Philip Zeyliger authored
Showing with 85 additions and 9 deletions.
  1. +26 −9 manifest.py
  2. +59 −0 shell-tests/follow_hash.sh
View
35 manifest.py
@@ -88,6 +88,7 @@ def __init__(self,
remotes=None,
tracking_branch=None, # the name of the tracking branch
remote_ref="master", # what ref to track
+ tracks_remote_ref=True,
from_remote="origin", # where to pull from
dir=None,
remote_project_name = None
@@ -98,6 +99,7 @@ def __init__(self,
self._dir = dir if dir else name
self.from_remote = from_remote
self.remote_ref = remote_ref
+ self.tracks_remote_ref = tracks_remote_ref
self.tracking_branch = tracking_branch
self.remote_project_name = remote_project_name if remote_project_name else name
@@ -122,15 +124,16 @@ def from_dict(manifest, name, data):
track_tag = data.get('track-tag')
track_branch = data.get('track-branch')
+ track_hash = data.get('track-hash')
- # This is old and deprecated
- ref = data.get('refspec')
- if track_tag and track_branch:
- raise Exception("Cannot specify both track-branch and track-tag for project %s" %
+ if len([ x for x in [track_tag, track_branch, track_hash] if x]) != 1:
+ raise Exception("Cannot specify more than one of track-branch, track-tag, or track-hash for project %s" %
name)
- if not track_tag and not track_branch:
+ # This is old and deprecated
+ ref = data.get('refspec')
+ if not track_tag and not track_branch and not track_hash:
if ref:
logging.warn("'ref' is deprecated - use either track-branch or track-tag " +
"for project %s" % name)
@@ -140,10 +143,16 @@ def from_dict(manifest, name, data):
if track_tag:
remote_ref = "refs/tags/" + track_tag
+ tracks_remote_ref = True
tracking_branch = track_tag
elif track_branch:
remote_ref = "%s/%s" % (from_remote, track_branch)
+ tracks_remote_ref = True
tracking_branch = track_branch
+ elif track_hash:
+ remote_ref = track_hash
+ tracks_remote_ref = False
+ tracking_branch = "crepo"
else:
assert False and "Cannot get here!"
@@ -152,6 +161,7 @@ def from_dict(manifest, name, data):
manifest=manifest,
remotes=my_remotes,
remote_ref=remote_ref,
+ tracks_remote_ref=tracks_remote_ref,
tracking_branch=tracking_branch,
dir=data.get('dir', name),
from_remote=from_remote,
@@ -201,8 +211,12 @@ def clone(self):
if repo.command(["show-ref", "-q", "HEAD"]) != 0:
# There is no HEAD (maybe origin/master doesnt exist) so check out the tracking
# branch
- repo.check_command(["checkout", "--track", "-b", self.tracking_branch,
- self.remote_ref])
+ if self.tracks_remote_ref:
+ repo.check_command(["checkout", "--track", "-b", self.tracking_branch,
+ self.remote_ref])
+ else:
+ repo.check_command(["checkout", "-b", self.tracking_branch,
+ self.remote_ref])
else:
repo.check_command(["checkout"])
@@ -234,8 +248,11 @@ def ensure_tracking_branch(self):
if branch_missing:
logging.warn("Branch %s does not exist in project %s. checking out." %
(self.tracking_branch, self.name))
- self.git_repo.command(["branch", "--track",
- self.tracking_branch, self.remote_ref])
+ if self.tracks_remote_ref:
+ self.git_repo.command(["branch", "--track",
+ self.tracking_branch, self.remote_ref])
+ else:
+ self.git_repo.command(["branch", self.tracking_branch, self.remote_ref])
def checkout_tracking_branch(self):
View
59 shell-tests/follow_hash.sh
@@ -0,0 +1,59 @@
+#!/bin/bash -x
+
+set -e
+
+DIRNAME=$(dirname $0)
+BINDIR=$(python -c "import os; print os.path.abspath('$DIRNAME')")
+CREPO=$BINDIR/../crepo.py
+
+TESTDIR=${TESTDIR:-/tmp/follow_hash.$$}
+mkdir -p $TESTDIR
+cd $TESTDIR
+
+
+################
+# REPO A
+################
+mkdir repo_a
+pushd repo_a
+git init
+echo "First commit" > file_a
+git add . && git commit -a -m '1'
+
+echo "Second commit" > file_b
+git add . && git commit -a -m '2'
+git tag commit_b
+COMMIT_B=$(git rev-parse commit_b)
+
+echo "Third commit" >> file_a
+git add . && git commit -a -m '3'
+
+REPO_A=`pwd`
+
+popd
+
+##############
+# Run crepo in a new dir
+##############
+mkdir tests
+pushd tests
+
+cat > manifest.json <<EOF
+{
+ "remotes":
+ {"origin": { "fetch": "$TESTDIR/%(name)s" }},
+
+ "projects":
+ {"repo_a": { "track-hash": "$COMMIT_B" }}
+}
+EOF
+
+$CREPO sync
+
+## Check that the checkout is correct
+pushd repo_a
+test $(git symbolic-ref HEAD) == "refs/heads/crepo"
+test $(git remote) == "origin"
+test -f file_a
+test -f file_b
+popd
Please sign in to comment.
Something went wrong with that request. Please try again.