Add files added to Skia HEAD in google3 to the Git repo.
[platform/upstream/libSkiaSharp.git] / tools / git_clone_to_google3.sh
1 #!/bin/bash
2 # Copyright 2014 Google Inc.
3 #
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # Crude script to clone the git skia repo into the current directory, which
8 # must be a CitC client.
9 #
10 # Usage:
11 #      ./tools/git_clone_to_google3.sh
12
13 source gbash.sh || exit
14 DEFINE_string skia_rev "" "Git hash of Skia revision to clone, default LKGR."
15
16 set -x -e
17
18 # To run this script after making edits, run:
19 # g4 revert -k git_clone_to_google3.sh
20 # To get the file back into your CL, run:
21 # g4 edit git_clone_to_google3.sh
22 #g4 opened | grep -q "//depot" && gbash::die "Must run in a clean client."
23
24 # Checkout LKGR of Skia in a temp location.
25 TMP=$(gbash::make_temp_dir)
26 pushd "${TMP}"
27 git clone https://skia.googlesource.com/skia
28 cd skia
29 git fetch
30 if [ -z "${FLAGS_skia_rev}" ]; then
31   # Retrieve last known good revision.
32   MY_DIR="$(gbash::get_absolute_caller_dir)"
33   FLAGS_skia_rev="$(${MY_DIR}/get_skia_lkgr.sh)"
34 fi
35 git checkout --detach "${FLAGS_skia_rev}"
36
37 # Rsync to google3 location.
38 popd
39 # Use multichange client in case there are too many files for nomultichange. http://b/7292343
40 g4 client --set_option multichange
41 # Use allwrite to simplify opening the correct files after rsync.
42 g4 client --set_option allwrite
43 # Filter directories added to CitC.
44 rsync -avzJ \
45   --delete \
46   --delete-excluded \
47   --include=/bench \
48   --include=/dm \
49   --include=/gm \
50   --include=/include \
51   --include=/src \
52   --exclude=/src/animator \
53   --include=/tests \
54   --include=/third_party \
55   --include=/tools \
56   --include=/.git \
57   '--exclude=/*/' \
58   --include=/third_party/etc1 \
59   --include=/third_party/ktx \
60   --include=/third_party/libwebp \
61   '--exclude=/third_party/*/' \
62   "${TMP}/skia/" \
63   "./"
64
65 # Open added/changed files for add/edit.
66 g4 reopen
67 # Revert files that are equivalent to the checked in version.
68 g4 revert -a
69
70 # Tell CitC to ignore .git and .gitignore.
71 find . \
72   \( -name .git \
73   -o -name .gitignore \
74   \) \
75   -execdir g4 revert -k \{\} \;
76
77 # Tell Git to ignore README.google and BUILD.
78 echo README.google >> .git/info/exclude
79 echo BUILD >> .git/info/exclude
80 g4 revert README.google
81 g4 revert BUILD
82
83 # Use google3 version of OWNERS, README.google, and BUILD.
84 find . \
85   \( -name OWNERS -o -name README.google -o -name BUILD \) \
86   -exec git update-index --skip-worktree \{\} \; \
87   -execdir g4 revert \{\} \;
88
89 # Tell git to ignore files left out of the rsync (i.e. "deleted" files).
90 git status --porcelain | \
91   grep -e "^ D" | \
92   cut -c 4- | \
93   xargs git update-index --skip-worktree
94