Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Unified Diff: gclient-new-workdir.py

Issue 52663008: Add a new gclient-new-workdir script which clones an existing gclient working directory much like g… (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient-new-workdir.py
diff --git a/gclient-new-workdir.py b/gclient-new-workdir.py
new file mode 100755
index 0000000000000000000000000000000000000000..be4ce7944758094a435f9e2bae36e4ac8b6425d7
--- /dev/null
+++ b/gclient-new-workdir.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Usage:
+# gclient-new-workdir.py <repository> <new_workdir> [<branch>]
+#
+
+import os
+import shutil
+import sys
+
+def main(argv):
+ if len(argv) < 3:
iannucci 2013/11/04 21:40:29 also check if not enough parameters? Shouldn't it
+ usage()
+ return 1
+
+ if not os.path.exists(argv[1]):
+ print("Repository does not exist: " + argv[1])
+ return 1
+
+ if os.path.exists(argv[2]):
+ print("New workdir already exists: " + argv[2])
+ return 1
+
+ repository = argv[1]
+ new_workdir = argv[2]
iannucci 2013/11/04 21:40:29 Let's move these above the checks, so we don't hav
+
+ gclient = repository + os.sep + ".gclient"
iannucci 2013/11/04 21:40:29 os.path.join(repository, '.gclient')
+ if not os.path.exists(gclient):
+ print("No .gclient file: " + gclient)
+
+ gclient_entries = repository + os.sep + ".gclient_entries"
+ if not os.path.exists(gclient_entries):
+ print("No .gclient_entries file: " + gclient_entries)
+
+ os.mkdir(new_workdir)
+ os.symlink(gclient, new_workdir + os.sep + ".gclient")
+ os.symlink(gclient_entries, new_workdir + os.sep + ".gclient_entries")
+
+ for root, dirs, files in os.walk(repository):
+ for name in dirs:
+ if name == ".git":
+ workdir = root.replace(repository, new_workdir, 1)
+ make_workdir(os.path.join(root, name), os.path.join(workdir, name))
+
+ return 0
+
+def make_workdir(repository, new_workdir):
+ print("Creating: " + new_workdir)
+ os.makedirs(new_workdir)
+ make_symlink(repository, new_workdir, "config")
+ make_symlink(repository, new_workdir, "refs")
+ if os.path.exists(repository + os.sep + "logs"):
+ os.makedirs(new_workdir + os.sep + "logs")
+ make_symlink(repository, new_workdir, "logs" + os.sep + "refs")
+ make_symlink(repository, new_workdir, "objects")
+ make_symlink(repository, new_workdir, "info")
+ make_symlink(repository, new_workdir, "hooks")
+ make_symlink(repository, new_workdir, "packed-refs")
+ make_symlink(repository, new_workdir, "remotes")
+ make_symlink(repository, new_workdir, "rr-cache")
+ make_symlink(repository, new_workdir, "svn")
+ shutil.copy2(repository + os.sep + "HEAD", new_workdir + os.sep + "HEAD")
+ before = os.getcwd()
+ os.chdir(new_workdir.rstrip(".git"))
+ os.system("git checkout -f")
iannucci 2013/11/04 21:40:29 let's just use subprocess.check_call with the cwd
+ os.chdir(before)
+
+def make_symlink(repository, new_workdir, link):
+ if not os.path.exists(repository + os.sep + link):
+ return
+ os.symlink(repository + os.sep + link, new_workdir + os.sep + link)
+
+def usage():
+ print("gclient-new-workdir.py <repository> <new_workdir>")
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698