aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Ed Baunton <edbaunton@gmail.com>2018-08-07 06:07:21 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-07 06:09:20 -0700
commit4ca4b4515a0e9e473a9c149c0aff40314b6bba74 (patch)
tree73ab45df39c6c51656cb0f11c285d91e33b43375 /tools
parent17fa6866cb565d0fdb823a8c244b372a30ea41e7 (diff)
Replace cd with git -C during in git skylark rules
Use `git -C` instead of `cd` in git skylark rules to be more concise. I think it's probably better to use the built-in changedir functionality of git rather than `cd`ing around manually. Happy to be overruled however if it makes readability better. Closes #5668. PiperOrigin-RevId: 207703326
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/repo/git.bzl14
1 files changed, 7 insertions, 7 deletions
diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl
index 99a6d6b79d..1e410df1d2 100644
--- a/tools/build_defs/repo/git.bzl
+++ b/tools/build_defs/repo/git.bzl
@@ -52,9 +52,10 @@ set -ex
rm -rf '{directory}' '{dir_link}'
git clone {shallow} '{remote}' '{directory}' || git clone '{remote}' '{directory}'
fi
- cd '{directory}'
- git reset --hard {ref} || ((git fetch {shallow} origin {ref}:{ref} || git fetch origin {ref}:{ref}) && git reset --hard {ref})
- git clean -xdf )
+ git -C '{directory}' reset --hard {ref} || \
+ ((git -C '{directory}' fetch {shallow} origin {ref}:{ref} || \
+ git -C '{directory}' fetch origin {ref}:{ref}) && git -C '{directory}' reset --hard {ref})
+ git -C '{directory}' clean -xdf )
""".format(
working_dir = ctx.path(".").dirname,
dir_link = ctx.path("."),
@@ -76,8 +77,7 @@ set -ex
if ctx.attr.init_submodules:
st = ctx.execute([bash_exe, "-c", """
set -ex
-( cd '{directory}'
- git submodule update --init --checkout --force )
+( git -C '{directory}' submodule update --init --checkout --force )
""".format(
directory = ctx.path("."),
)], environment = ctx.os.environ)
@@ -88,14 +88,14 @@ set -ex
actual_commit = ctx.execute([
bash_exe,
"-c",
- "(cd '{directory}' && git log -n 1 --pretty='format:%H')".format(
+ "(git -C '{directory}' log -n 1 --pretty='format:%H')".format(
directory = ctx.path("."),
),
]).stdout
shallow_date = ctx.execute([
bash_exe,
"-c",
- "(cd '{directory}' && git log -n 1 --pretty='format:%cd' --date='format:%Y-%m-%d')".format(
+ "(git -C '{directory}' log -n 1 --pretty='format:%cd' --date='format:%Y-%m-%d')".format(
directory = ctx.path("."),
),
]).stdout