Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1159 create mirror of private GitHub repository #1161

Merged
merged 5 commits into from
Mar 9, 2015

Conversation

eugenk
Copy link
Member

@eugenk eugenk commented Jan 16, 2015

Updated message

This fixes #1159 and a few other git/cloning related bugs (see first commits).
When a private git repository is supposed to be cloned, git usually asks for credentials. This prompt is prevented by asking /bin/true for them. Of course, true doesn't supply any, but exits with code SUCCESS, so git thinks they are supplied and fails because the credentials don't fit to the repository.

I removed the previous workaround-commits by rebase (see original message).

Original message

This is more of a workaround than a fix for #1159.

I don't see any fast way to check if something is a git repository than git ls-remote. However, this asks for credentials when calling it on a github private repository.

I tried to read the login prompt of git ls-remote in Subprocess.run, but I could not get my hands on the prompt lines. Neither with IO.popen nor with Open3.popen2e.

The best solution would be to read those login prompt lines and abort if they are present, but I can't figure out how to do this, because they are not printed to stdout nor stderr of the child process.

end
end

class SourceTypeValidator < ActiveModel::Validator
def validate(record)
if record.mirror? && !record.source_type.present?
record.errors[:source_address] = "not a valid remote repository (types supported: #{SOURCE_TYPES.join(', ')})"
record.errors[:source_address] = "not a valid remote repository or not accessible (types supported: #{SOURCE_TYPES.join(', ')})"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [136/80]

@eugenk eugenk force-pushed the 1159-create_mirror_of_private_github_repository branch from 6db3ea7 to aa516e2 Compare January 16, 2015 11:00
@eugenk
Copy link
Member Author

eugenk commented Feb 3, 2015

Other possibilities to take a look at include

  • expect/autoexpect
  • output redirection via script -q -c 'git ls-remote private_repo' > output_file (only works on linux)

@jelmd
Copy link

jelmd commented Feb 3, 2015

Not sure, what you are trying to accomplish, but "command ...| tee file" could be a posix conform aka *x compatible thing you are looking for.

@eugenk
Copy link
Member Author

eugenk commented Feb 3, 2015

The thing is, that git ls-remote https://github.com/some_user/private_repository.git asks for a username and a password and I want to get my hands on the output asking for the credentials. This output is neither going to stdout not to stderr, but I need it to go to stdout/stderr. Otherwise I cannot access it from inside ruby while the process is running.

@jelmd
Copy link

jelmd commented Feb 3, 2015

Hmmm, but script just captures stdout and stderr (I guess the > is just a typo), the | stdout [and stderr if redirected], only. So if you wanna capture both in a file (and not directly from stdout,stderr), command ... >file 2>&1 redirection is sufficient. Anyway, if you say, you do not get anything via stdout/stderr than whatever of the previous things one does, one would always get an empty file.

So the only thing what would explain that, is IMHO, that the related fds get closed on exec - possible, but I doubt that. Have you a conrete working snippet, which I can use for playing around ...?

@tillmo
Copy link
Member

tillmo commented Feb 3, 2015

"neither stdout nor stderr" here means the usual practice of many commands that the password prompt is directly sent to the tty, bypassing stdout/stderr and any redirections of these. Commands like expect redirect this using a pty.

@eugenk
Copy link
Member Author

eugenk commented Feb 3, 2015

You can directly try git ls-remote https://github.com/some_user/private_repository.git (yes, with "some_user"). This prompts for credentials.

FYI: I used > to illustrate the redirection. In ruby, I call either IO.popen or popen2e to spawn a process and read from stdout and stderr. There are no shell builtins accessible like > or |.

I successfully tried script -q -c ... on an arch linux and it put the output into a file. This is not a good solution, though, because it's only working on linux and not on osx (some developers here use osx).

@jelmd
Copy link

jelmd commented Feb 3, 2015

What about abusing GIT_ASKPSS? E.g.:

echo '#!/bin/sh\nprint "$@" >/tmp/out.txt' >/tmp/ask.sh
chmod 755 /tmp/ask.sh
export GIT_ASKPSS=/tmp/ask.sh
git ls-remote ...

Fore more see http://code.metager.de/source/xref/git/prompt.c#44 ;-)

@eugenk
Copy link
Member Author

eugenk commented Feb 4, 2015

The script as you posted does not work for me. However, it's a very good pointer to GIT_ASKPASS. Thanks!

This does exactly what I'm looking for (because we don't want to use credentials at this point):

GIT_ASKPASS=echo git ls-remote https://github.com/some_user/private_repository.git

@eugenk eugenk force-pushed the 1159-create_mirror_of_private_github_repository branch from 2a2bd54 to 9dc3212 Compare February 4, 2015 09:08
@eugenk
Copy link
Member Author

eugenk commented Feb 4, 2015

Now the pull request is ready for review. In my opinion, it's a fix for the problem and not a workaround anymore.

elsif GitRepository.is_svn_repository?(source_address)
self.source_type = 'svn'
if source_address?
if GitRepository.is_git_repository?(source_address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do the following instead:

self.source_type =
  if GitRepository.is_git_repository?(source_address)
    'git'
  ....

@eugenk
Copy link
Member Author

eugenk commented Mar 3, 2015

I ignore the hound comments after the last commit because they don't match to our style guide (and hound has the hiccups).

@eugenk eugenk force-pushed the 1159-create_mirror_of_private_github_repository branch from f54192f to 6370334 Compare March 4, 2015 21:20
@0robustus1
Copy link
Contributor

👍

eugenk added a commit that referenced this pull request Mar 9, 2015
…ithub_repository

1159 create mirror of private GitHub repository
@eugenk eugenk merged commit e27d581 into staging Mar 9, 2015
@eugenk eugenk deleted the 1159-create_mirror_of_private_github_repository branch March 9, 2015 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'Create Repository' feature is not working
5 participants