3

I've got a little perl-script which attempts to pull from a git repository and then gets some things from git log:

 use Git::Repository;
 my $repo = Git::Repository->new(
         git_dir => $git_path,
 );
 $repo->run('pull') || die $!;
 my @commits = $repo->run(log);
 ...

For the authentication I have a .netrc-file with my credentials in /home/bla. This works perfectly when the script is run from the shell. Now I've tried to use this script for a web-application:

my $evil_commits = `./list_commits.pl`;

When I do this it yields the following error message:

[Thu Sep 19 12:50:49 2013] [error] [client <>] fatal: Could not read password: No such device or address at ./list_commits.pl line 45

I've already tried to set $ENV{HOME} inside the CGI-script but that doesn't help. Any suggestions on what I'm missing here?

Vince
  • 1,517
  • 2
  • 18
  • 43
  • Does your web-app runs with the same user account as the one where `~/.netrc` is? – VonC Sep 19 '13 at 12:17
  • Nope, but I can't imagine how that makes any difference, since I changed `$ENV{HOME}` to the right directory and I don't get an error saying `permission denied`. Even `chmod 777` on the `.netrc`-file doesn't change anything. I can hardly imagine that this error is related to the user running the script. – Vince Sep 19 '13 at 12:38
  • I would say, it does make the difference. – VonC Sep 19 '13 at 13:39
  • Could you please also explain why this exact error could be caused by the fact that the users are different instead of just stating, that it 'does make the difference'? And maybe even providing a solution other than "change the user", because that's not possible for me as I don't have administration privileges on the machine. – Vince Sep 19 '13 at 13:43
  • I suspect the `curl` library (ultimately called by a `git pull`) which relies on `netrc` for credential **looks for it in `~/.netrc`, not in `$HOME/.netrc`** (and [the two can be different](http://stackoverflow.com/a/1660054/6309)). I don't have a solution just now, though. – VonC Sep 19 '13 at 13:59
  • That indeed sounds reasonable. I didn't know that `$HOME != ~`... – Vince Sep 19 '13 at 14:00
  • The [difference is also illustrated here](http://stackoverflow.com/q/11587343/6309). – VonC Sep 19 '13 at 14:01

1 Answers1

0

You could try to print the current directory from withhin the script. That way you will be able to change the path in a way that makes it pointing to the corrent file.


Apart from that, i recommend you using ssh-keys. You won't need any password files in that case.

functionpointer
  • 1,411
  • 1
  • 13
  • 18
  • Both scripts are in the same directory, so that's not the problem. The `list_commits.pl`-script is ran and dies because of the `$repo->run('pull') || die $!;`. – Vince Sep 19 '13 at 11:16