Skip to content

Commit

Permalink
Add fetch strategy if bare repository already exists locally
Browse files Browse the repository at this point in the history
  • Loading branch information
countzero committed Jun 2, 2019
1 parent 988a936 commit 768bf99
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backup_github_repositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ function Write-Message([string] $message, [string] $color = 'Yellow') {
}

#
# Clone a remote GitHub repository into a local directory.
# Clone or fetch a remote GitHub repository into a local directory.
#
# @see https://git-scm.com/docs/git-clone#git-clone---mirror
#
function Backup-GitHubRepository([string] $fullName, [string] $directory) {

Write-Message "Starting backup of https://github.com/${fullName} to ${directory}..." 'DarkYellow'

if (Test-Path "${directory}") {

git --git-dir="${directory}" fetch --all
git --git-dir="${directory}" fetch --tags
return
}

git clone --mirror "[email protected]:${fullName}.git" "${directory}"
}

Expand Down

0 comments on commit 768bf99

Please sign in to comment.