Skip to content

Commit

Permalink
feat: Allow pulling translations from a commit hash
Browse files Browse the repository at this point in the history
By switching from clone to an explicit init+fetch we can get better control
of what commits are fetched. clone only allows targeting a branch or a
tag, but fetch can ask for any commit. The caveat is that the server needs
to allow this via `uploadpack.allowReachableSHA1InWant` and similar.

Minor changes:

- checkout is now also quiet by default

See #48
  • Loading branch information
timmc-edx committed Dec 20, 2024
1 parent 9ea96b6 commit fc97445
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ regularly and useful to understand ``atlas`` at a glance.
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.
`-n` or `--revision`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.
Git revision to pull from. Support branches, tags, and commits hashes. Defaults to 'main'.
This option name used to be `-b` or `--branch`. The deprecated name will be removed in a future release.
Expand Down
21 changes: 9 additions & 12 deletions atlas
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Options:
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.
\`-n\` or \`--revision\`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.
Git revision to pull from. Support branches, tags, and commits hashes. Defaults to 'main'.
This option name used to be \`-b\` or \`--branch\`. The deprecated name will be removed in a future release.
Expand Down Expand Up @@ -200,7 +200,7 @@ Options:
slug of the GitHub repository to pull from. Defaults 'openedx/openedx-translations'.
`-n` or `--revision`:
Git revision to pull from. Currently only branches and tags are supported. Defaults to 'main'.
Git revision to pull from. Support branches, tags, and commits hashes. Defaults to 'main'.
This option name used to be `-b` or `--branch`. The deprecated name will be removed in a future release.
Expand Down Expand Up @@ -507,18 +507,15 @@ pull_translations() {
quiet="--quiet"
fi

if [ "$pull_revision" ];
then
pull_revision_argument="--branch=${pull_revision}"
else
pull_revision_argument=""
fi

# Creating a shallow clone of the repo without without pulling the files yet
# shellcheck disable=SC2086
git clone $quiet $pull_revision_argument --filter=blob:none --no-checkout --depth=1 \
"https://github.com/${pull_repository}.git" translations_TEMP || exit
git init $quiet translations_TEMP || exit
cd translations_TEMP || exit
git remote add origin "https://github.com/${pull_repository}.git" || exit
# Requires server to allow pulling commits by direct commit hash reference,
# controlled by uploadpack.allowAnySHA1InWant and related configs. (GitHub
# does allow this, though.)
git fetch $quiet --filter=blob:none --depth=1 origin "${pull_revision:-main}" || exit

# finished "Creating a temporary Git repository to pull translations into <temp dir>..." step
if [ -z "$SILENT" ];
Expand Down Expand Up @@ -564,7 +561,7 @@ pull_translations() {
fi

# Retrieve translation files from the repo
git checkout HEAD
git checkout $quiet FETCH_HEAD

# Remove .git directory
rm -rf .git
Expand Down

0 comments on commit fc97445

Please sign in to comment.