Skip to content

Commit 20093b5

Browse files
authored
feat: update clones if they're present (#61)
1 parent 99b3a7e commit 20093b5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/MultiDocumenter.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,28 @@ function maybe_clone(docs::Vector{MultiDocRef})
246246
if !isdir(doc.upstream)
247247
@info "Upstream at $(doc.upstream) does not exist. `git clone`ing `$(doc.giturl)#$(doc.branch)`"
248248
run(
249-
`$(git()) clone --depth 1 $(doc.giturl) --branch $(doc.branch) --single-branch $(doc.upstream)`,
249+
`$(git()) clone --depth 1 $(doc.giturl) --branch $(doc.branch) --single-branch --no-tags $(doc.upstream)`,
250250
)
251+
else
252+
git_dir, git_worktree = abspath(joinpath(doc.upstream, ".git")), abspath(doc.upstream)
253+
if !isdir(git_dir)
254+
@warn "Unable to update existing clone at $(doc.upstream): .git/ directory missing"
255+
continue
256+
end
257+
@info "Updating existing clone at $(doc.upstream)"
258+
gitcmd = `$(git()) -C $(git_worktree) --git-dir=$(git_dir)`
259+
try
260+
if !success(`$(gitcmd) diff HEAD --exit-code`)
261+
@warn "Existing clone at $(doc.upstream) has local changes -- not updating."
262+
continue
263+
end
264+
run(`$(gitcmd) fetch origin $(doc.branch)`)
265+
run(`$(gitcmd) checkout --detach origin/$(doc.branch)`)
266+
catch e
267+
# We're only interested in catching `git` errors here
268+
isa(e, ProcessFailedException) || rethrow()
269+
@error "Unable to update existing clone at $(doc.upstream)" exception = (e, catch_backtrace())
270+
end
251271
end
252272
end
253273
end

0 commit comments

Comments
 (0)