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
4 changes: 4 additions & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ All changes included in 1.7:

- ([#12366](https://github.com/quarto-dev/quarto-cli/pull/12366)): Added Bulgarian translation for Quarto UI text (credit: @sakelariev)

## `quarto publish`

- ([#9929](https://github.com/quarto-dev/quarto-cli/issues/9929)): `quarto publish gh-pages` will now clean previous worktree directory leftover from previous deploys.

## Other Fixes and Improvements

- A new folder `quarto-session-temp` can be created in `.quarto` to store temporary files created by Quarto during a rendering. Reminder: `.quarto` is for internal use of Quarto and should not be versioned (thus added to `.gitignore`).
Expand Down
32 changes: 29 additions & 3 deletions src/publish/gh-pages/gh-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2020-2022 Posit Software, PBC
*/

import { info } from "../../deno_ral/log.ts";
import { debug, info } from "../../deno_ral/log.ts";
import { dirname, join, relative } from "../../deno_ral/path.ts";
import { copy } from "../../deno_ral/fs.ts";
import * as colors from "fmt/colors";
Expand Down Expand Up @@ -33,6 +33,8 @@ import {
gitHubContextForPublish,
verifyContext,
} from "../common/git.ts";
import { createTempContext } from "../../core/temp.ts";
import { projectScratchPath } from "../../project/project-scratch.ts";

export const kGhpages = "gh-pages";
const kGhpagesDescription = "GitHub Pages";
Expand Down Expand Up @@ -189,12 +191,35 @@ async function publish(
type === "site" ? target?.url : undefined,
);

const kPublishWorktreeDir = "quarto-publish-worktree-";
// allocate worktree dir
const tempDir = Deno.makeTempDirSync({ dir: input });
const temp = createTempContext(
{ prefix: kPublishWorktreeDir, dir: projectScratchPath(input) },
);
const tempDir = temp.baseDir;
removeIfExists(tempDir);

const deployId = shortUuid();
// cleaning up leftover by listing folder with prefix .quarto-publish-worktree- and calling git worktree rm on them
const worktreeDir = Deno.readDirSync(projectScratchPath(input));
for (const entry of worktreeDir) {
if (
entry.isDirectory && entry.name.startsWith(kPublishWorktreeDir)
) {
debug(
`Cleaning up leftover worktree folder ${entry.name} from past deploys`,
);
const worktreePath = join(projectScratchPath(input), entry.name);
await execProcess({
cmd: ["git", "worktree", "remove", worktreePath],
cwd: projectScratchPath(input),
});
removeIfExists(worktreePath);
}
}

// create worktree and deploy from it
const deployId = shortUuid();
debug(`Deploying from worktree ${tempDir} with deployId ${deployId}`);
await withWorktree(input, relative(input, tempDir), async () => {
// copy output to tempdir and add .nojekyll (include deployId
// in .nojekyll so we can poll for completed deployment)
Expand All @@ -209,6 +234,7 @@ async function publish(
["push", "--force", "origin", "HEAD:gh-pages"],
]);
});
temp.cleanup();
info("");

// if this is the creation of gh-pages AND this is a user home/default site
Expand Down
Loading