Skip to content
Open
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ This is some content

### Delete orphaned files

With the `deleteOrphaned` option you can choose to delete files in the target repository if they are deleted in the source repository. The option defaults to `false` and only works when [syncing entire directories](#sync-entire-directories):
With the `deleteOrphaned` option you can choose to delete files in the target repository if they are deleted in the
source repository. The option defaults to `false` works either when [syncing entire directories](#sync-entire-directories), or specific
files:

```yml
user/repo:
Expand All @@ -264,8 +266,6 @@ user/repo:
deleteOrphaned: true
```

It only takes effect on that specific directory.

### Sync the same files to multiple repositories

Instead of repeating yourself listing the same files for multiple repositories, you can create a group:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ export default class Git {
)
}

async remove(file) {
return execCmd(
`git rm -f "${ file }"`,
this.workingDir
)
}

isOneCommitPush() {
return github.context.eventName === 'push' && github.context.payload.commits.length === 1
}
Expand Down
32 changes: 23 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,36 @@ async function run() {
// Loop through all selected files of the source repo
await forEach(item.files, async (file) => {
const fileExists = fs.existsSync(file.source)
if (fileExists === false) return core.warning(`Source ${ file.source } not found`)

const localDestination = `${ git.workingDir }/${ file.dest }`

const destExists = fs.existsSync(localDestination)
if (destExists === true && file.replace === false) return core.warning(`File(s) already exist(s) in destination and 'replace' option is set to false`)
let isDirectory

if (fileExists === false) {
// if there is no local file, then we assume it's not a directory
isDirectory = false

if (!file.deleteOrphaned) {
return core.warning(`Source ${ file.source } not found`)
}

const isDirectory = await pathIsDirectory(file.source)
const source = isDirectory ? `${ addTrailingSlash(file.source) }` : file.source
const dest = isDirectory ? `${ addTrailingSlash(localDestination) }` : localDestination
if (destExists === true) {
await git.remove(file.dest)
}
} else {
isDirectory = await pathIsDirectory(file.source)

if (destExists === true && file.replace === false) return core.warning(`File(s) already exist(s) in destination and 'replace' option is set to false`)

if (isDirectory) core.info(`Source is directory`)
const source = isDirectory ? `${ addTrailingSlash(file.source) }` : file.source
const dest = isDirectory ? `${ addTrailingSlash(localDestination) }` : localDestination

await copy(source, dest, isDirectory, file)
if (isDirectory) core.info(`Source is directory`)

await git.add(file.dest)
await copy(source, dest, isDirectory, file)

await git.add(file.dest)
}

// Commit each file separately, if option is set to false commit all files at once later
if (COMMIT_EACH_FILE === true) {
Expand Down