这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/deployment/methods/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ git:from-archive [--archive-type ARCHIVE_TYPE] <app> <archive-url> [<git-usernam
git:from-image [--build-dir DIRECTORY] <app> <docker-image> [<git-username> <git-email>] # Updates an app's git repository with a given docker image
git:generate-deploy-key # Generates a deploy ssh key
git:load-image [--build-dir DIRECTORY] <app> <docker-image> [<git-username> <git-email>] # Updates an app's git repository with a docker image loaded from stdin
git:sync [--build] <app> <repository> [<git-ref>] # Clone or fetch an app from remote git repo
git:sync [--build|build-if-changes] <app> <repository> [<git-ref>] # Clone or fetch an app from remote git repo
git:initialize <app> # Initialize a git repository for an app
git:public-key # Outputs the dokku public deploy key
git:report [<app>] [<flag>] # Displays a git report for one or more apps
Expand Down Expand Up @@ -157,6 +157,12 @@ By default, this command does not trigger an application build. To do so during
dokku git:sync --build node-js-app https://github.com/heroku/node-js-getting-started.git
```

When running `git:sync` without a reference, it may be useful to only build when there are changes. To do so, specify the `--build-if-changes` flag.

```shell
dokku git:sync --build-if-changes node-js-app https://github.com/heroku/node-js-getting-started.git
```

### Initializing from private repositories

> [!IMPORTANT]
Expand Down
23 changes: 23 additions & 0 deletions plugins/git/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ cmd-git-sync() {
local cmd="git:sync"
[[ "$1" == "$cmd" ]] && shift 1
declare APP GIT_REMOTE GIT_REF FLAG
local CURRENT_REF DOKKU_DEPLOY_BRANCH SHOULD_BUILD UPDATED_REF

ARGS=()
for arg in "$@"; do
Expand All @@ -187,6 +188,11 @@ cmd-git-sync() {
continue
fi

if [[ "$arg" == "--build-if-changes" ]]; then
FLAG="--build-if-changes"
continue
fi

ARGS+=("$arg")
done

Expand All @@ -202,14 +208,31 @@ cmd-git-sync() {
fi

local APP_ROOT="$DOKKU_ROOT/$APP"

DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
CURRENT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)"

if [[ "$(fn-git-cmd "$APP_ROOT" count-objects)" == "0 objects, 0 kilobytes" ]]; then
dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF"
fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF"
else
fn-git-fetch "$APP" "$GIT_REMOTE" "$GIT_REF"
fi

UPDATED_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)"
local SHOULD_BUILD=false
if [[ "$FLAG" == "--build" ]]; then
SHOULD_BUILD=true
elif [[ "$FLAG" == "--build-if-changes" ]]; then
if [[ "$CURRENT_REF" == "$UPDATED_REF" ]]; then
dokku_log_verbose "Skipping build as no changes were detected"
return
fi

SHOULD_BUILD=true
fi

if [[ "$SHOULD_BUILD" == "true" ]]; then
if [[ -n "$GIT_REF" ]]; then
GIT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$GIT_REF")"
plugn trigger receive-app "$APP" "$GIT_REF"
Expand Down
Loading