Repository: impala
Updated Branches:
  refs/heads/master 5b824408a -> ab75dd12e


test-with-docker: work with git worktree

This commit adds a little of git-wrangling to allow test-with-docker to
work when invoked from git directories managed by "git worktree". These
are different in that they reference another git directory elsewhere on
the file system, which also needs to be mounted into the container.

Change-Id: I9186e0b6f068aacc25f8d691508165c04329fa8b
Reviewed-on: http://gerrit.cloudera.org:8080/10335
Reviewed-by: Joe McDonnell <joemcdonn...@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/6454b74d
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/6454b74d
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/6454b74d

Branch: refs/heads/master
Commit: 6454b74d2e299415d49fb8d9e1a099857830403c
Parents: 5b82440
Author: Philip Zeyliger <phi...@cloudera.com>
Authored: Fri May 4 21:03:48 2018 -0700
Committer: Impala Public Jenkins <impala-public-jenk...@cloudera.com>
Committed: Fri May 18 02:18:38 2018 +0000

----------------------------------------------------------------------
 docker/entrypoint.sh       |  2 +-
 docker/test-with-docker.py | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/6454b74d/docker/entrypoint.sh
----------------------------------------------------------------------
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index d57cb5e..1243e28 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -169,7 +169,7 @@ function build_impdev() {
   mkdir /home/impdev/Impala
   pushd /home/impdev/Impala
   git init
-  git fetch /repo --no-tags HEAD
+  git fetch /git_common_dir --no-tags "$GIT_HEAD_REV"
   git checkout -b test-with-docker FETCH_HEAD
 
   # Link in logs. Logs are on the host since that's the most important thing to

http://git-wip-us.apache.org/repos/asf/impala/blob/6454b74d/docker/test-with-docker.py
----------------------------------------------------------------------
diff --git a/docker/test-with-docker.py b/docker/test-with-docker.py
index c3f4427..fa230e8 100755
--- a/docker/test-with-docker.py
+++ b/docker/test-with-docker.py
@@ -414,6 +414,20 @@ class TestWithDocker(object):
     self.name = name
     self.containers = []
     self.git_root = _check_output(["git", "rev-parse", 
"--show-toplevel"]).strip()
+
+    # If using worktrees, we need to find $GIT_COMMON_DIR; rev-parse
+    # supports finding it as of vesion 2.5.0; for older versions, we
+    # use $GIT_DIR.
+    git_common_dir = _check_output(["git", "rev-parse", 
"--git-common-dir"]).strip()
+    if git_common_dir == "--git-common-dir":
+      git_common_dir = _check_output(["git", "rev-parse", "--git-dir"]).strip()
+    self.git_common_dir = os.path.realpath(git_common_dir)
+    assert os.path.exists(self.git_common_dir)
+
+    self.git_head_rev = _check_output(
+        ["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
+    assert self.git_head_rev, \
+        "Could not get reference to HEAD using git rev-parse --abbrev-ref 
HEAD."
     self.cleanup_containers = cleanup_containers
     self.cleanup_image = cleanup_image
     self.image = None
@@ -476,8 +490,13 @@ class TestWithDocker(object):
         "-e", "LC_ALL=C",
         "-e", "IMPALAD_MEM_LIMIT_BYTES=" +
         str(self.impalad_mem_limit_bytes),
-        # Mount the git directory so that clones can be local
+        # Mount the git directory so that clones can be local.
+        # We use /repo to have access to certain scripts,
+        # and we use /git_common_dir to have local clones,
+        # even when "git worktree" is being used.
         "-v", self.git_root + ":/repo:ro",
+        "-v", self.git_common_dir + ":/git_common_dir:ro",
+        "-e", "GIT_HEAD_REV=" + self.git_head_rev,
         "-v", self.ccache_dir + ":/ccache",
         # Share timezone between host and container
         "-v", "/etc/localtime:/mnt/localtime",

Reply via email to