Sync to latest from aosp master

bug:22636165

Change-Id: Iccf99b34047273f277eae53ef9614e3e562ece4d
diff --git a/update.py b/update.py
index abcad9e..8a66066 100755
--- a/update.py
+++ b/update.py
@@ -28,17 +28,21 @@
   if p.wait() != 0:
     print 'Failed to checkout source from upstream git.'
     sys.exit(1)
-  
-  shutil.rmtree(os.path.join(trace_viewer_dir, '.git'), True)
 
+  trace_viewer_git_dir = os.path.join(trace_viewer_dir, '.git')
   # Update the UPSTREAM_REVISION file
   git_args = ['git', 'rev-parse', 'HEAD']
-  p = subprocess.Popen(git_args, stdout=subprocess.PIPE, cwd=trace_viewer_dir)
+  p = subprocess.Popen(git_args,
+                       stdout=subprocess.PIPE,
+                       cwd=trace_viewer_dir,
+                       env={"GIT_DIR":trace_viewer_git_dir})
   out, err = p.communicate()
   if p.wait() != 0:
     print 'Failed to get revision.'
     sys.exit(1)
 
+  shutil.rmtree(trace_viewer_git_dir, True)
+
   rev = out.strip()
   with open('UPSTREAM_REVISION', 'wt') as f:
     f.write(rev + '\n')