Skip to content

Commit 04ff728

Browse files
committed
Enable access to private repos
1 parent 6322da5 commit 04ff728

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

bin/github-backup

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ Options:
6565
EOF
6666
exit;
6767
}
68+
69+
# If cloning private repos it is necessary to pass the authentication
70+
# information to the git command. It is not possible to do this using
71+
# Git::Repository, so an alternative is to use git's GIT_ASKPASS option, which
72+
# is a command to run that will return the password (it is not possible to pass
73+
# the password directly in an environment variable). The github_backup_pass
74+
# command simply echos the GITHUB_TOKEN value, which can be used in place of a
75+
# password for authentication, thus allowing access to the private repos. This
76+
# option is ignored if it doesn't exist or returns nothing.
77+
$ENV{GIT_ASKPASS}="github_backup_pass";
78+
6879
my $gh = Github::Backup->new(
6980
api_user => $opts{user},
7081
token => $opts{token},

bin/github-backup-pass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo $GITHUB_TOKEN

lib/Github/Backup.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ Mandatory: Your Github username.
284284
285285
Mandatory: Your Github API token. If you wish to not include this on the
286286
command line, you can put the token into the C<GITHUB_TOKEN> environment
287-
variable.
287+
variable. Specifying the token in the C<GITHUB_TOKEN> environment variable also
288+
enables private repositories to be accessed, as github_backup will use the
289+
environment variable via the github_backup_pass command and git's
290+
C<GIT_ASKPASS> option to pass the required authentication information to git
291+
when cloning a repository.
288292
289293
=head2 -l | --list
290294

0 commit comments

Comments
 (0)