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

Feature/git fork #628

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Feature/git fork #628

wants to merge 6 commits into from

Conversation

hickey
Copy link

@hickey hickey commented Feb 3, 2017

Added support for forking on instances of Github other than github.com.

In addition added ability to pull stored settings from git config so that one is not prompted each time for things like username and such.

Also introduced a self documenting way of including helper scripts into the generated scripts. See the Makefile and helper/config-value for details. Also helps keeping one from forgetting to update the needs_* files.

bin/git-fork Outdated

if [[ -z "$token" ]]; then
echo "Enter github password"
read password
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer let curl ask for my password instead of passing it in the option.

Copy link
Author

Choose a reason for hiding this comment

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

Understandable. Although one is already being asked for the MFA code. Does that make sense to be asked for the MFA code before the password?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hickey
I think the order is not critical. Just because let curl ask for your password is simpler.

bin/git-fork Outdated
@@ -55,6 +90,12 @@ if [ "$origin" = true ]; then
else
# clone forked repo into current dir
git clone "${remote_prefix}${user}/${project}.git" "$project"
until [[ -d "$project" ]]; do
echo "Github is being slow today. Waiting 10 secs to attempt clone."
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are various causes that should be responsible for the failure of git clone.
Fortunately, the error message from git clone is clear enough.
Better shorten the message and remove our guess.

Copy link
Author

Choose a reason for hiding this comment

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

The issue I see there is that git clone is very verbose and just adds a lot of cruf to the terminal that does not need to be there (see below). Although I just realized that I should be sending stderr to /dev/null to avoid the excess cruf.

Since the fork is asynchronous there is no way to determine when the fork is complete other than trying it. If I execute the fork command against github.com, the repo exists by the time that the clone is attempted. But if I try the fork command against the internal Github Enterprise instance, I end up waiting at least once for the fork to complete. (probably the fast LAN vs 200 ms across the net).

The more that I think about it, the attempt to clone should probably only be attempted for about a minute or so. After that point the command should exit with an error code and a message that the repo could not be cloned locally.

0:128 ᐅ git clone git@github.com:hickey/fioo.git foo  
Cloning into 'foo'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

bin/git-fork Outdated
@@ -55,6 +90,12 @@ if [ "$origin" = true ]; then
else
# clone forked repo into current dir
git clone "${remote_prefix}${user}/${project}.git" "$project"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could check if $project exists before cloning into it?

Copy link
Author

Choose a reason for hiding this comment

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

Git clone will not allow one to clone over an already existing repo directory.

0:0 ᐅ git clone git@github.com:hickey/git-extras.git git-extras
fatal: destination path 'git-extras' already exists and is not an empty directory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hickey
Ah ha, this idea is inspired by your -d $project check.
If there is $project already, we can directly exit the script, skip git clone, cd, and so on.

bin/git-fork Outdated
@@ -55,6 +90,12 @@ if [ "$origin" = true ]; then
else
# clone forked repo into current dir
git clone "${remote_prefix}${user}/${project}.git" "$project"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hickey
Ah ha, this idea is inspired by your -d $project check.
If there is $project already, we can directly exit the script, skip git clone, cd, and so on.

@hickey
Copy link
Author

hickey commented Feb 4, 2017

Added better detection when the fork fails (which is really a comms error with talking to Github).

If directory already exists, clone will silently fail and the upstream references will be created. If they already exist, then a warning message is printed that it exists.

@hickey
Copy link
Author

hickey commented Feb 4, 2017

If you would prefer, I can squash all the commits and resubmit the PR.

cd "$project"
git remote add upstream "${remote_prefix}${owner}/${project}.git"
git fetch upstream
git clone "${remote_prefix}${user}/${project}.git" "$project" 2>/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that the output of git clone is cumbersome, but still think we should not hide the error message. They are like low level log, which may be useful sometimes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still insist the need for the output of git clone.

until [[ (( "$total_wait" > 60 )) || -d "$project" ]]; do
echo "Github is being slow today. Waiting $timeout secs to attempt clone."
sleep ${timeout[0]}
total_wait=$(expr $total_wait + ${timeout[0]})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to use total_wait=$((total_wait + timeout[0])), which is more modern.

Copy link
Author

Choose a reason for hiding this comment

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

I thought about that, but some of the older shells don't understand the double parenthesis. So I opted for the more traditional form.

# Check to make sure we cloned the repo. Backoff exponetially and try again
timeout=( 2 2 2 6 6 6 20 20 )
total_wait=0
until [[ (( "$total_wait" > 60 )) || -d "$project" ]]; do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, it will wait for 64(44 plus the last 20) seconds.

man/git-fork.1 Outdated
@@ -40,7 +40,71 @@ adds the forked repo as a remote called \fBorigin\fR
.P
Remotes will use ssh if you have it configured with GitHub, if not, https will be used\.
.
.P
Your Github settings can not be saved as git config values instead of specifying them each time\. To enable this you need to execute a few git config commands like the following\.
Copy link

Choose a reason for hiding this comment

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

I believe you meant now rather than "not be saved" here.

@@ -99,8 +99,52 @@ <h2 id="DESCRIPTION">DESCRIPTION</h2>

<p> Remotes will use ssh if you have it configured with GitHub, if not, https will be used.</p>

<p> Your Github settings can not be saved as git config values instead of
Copy link

@sacres sacres Feb 15, 2017

Choose a reason for hiding this comment

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

And here as well: s/not be saved/now be saved/

man/git-fork.md Outdated
@@ -21,8 +21,49 @@ git-fork(1) -- Fork a repo on github

Remotes will use ssh if you have it configured with GitHub, if not, https will be used.

Your Github settings can not be saved as git config values instead of
Copy link

@sacres sacres Feb 15, 2017

Choose a reason for hiding this comment

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

And here as well: s/not be saved/now be saved/

@hickey
Copy link
Author

hickey commented Apr 2, 2017

Sorry, I have been busy and this PR fell off the list. Updated wording in the documentation and surprised that I missed that typo. Thanks.

@hickey
Copy link
Author

hickey commented Apr 2, 2017

Let me know if you would like this PR squashed.

# set_config_value "key" "value" "global|system" (global or system not required)
set_config_value() {
$(git config ${3+--$3} git-extras.$1 $2)
echo $?
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO, I prefer to use git config ${3+--$3} git-extras.$1 $2 directly.
When writing shell script, people are more relied on $? that the return value to check if the previous command succeeded.

cd "$project"
git remote add upstream "${remote_prefix}${owner}/${project}.git"
git fetch upstream
git clone "${remote_prefix}${user}/${project}.git" "$project" 2>/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still insist the need for the output of git clone.

@adriaanzon
Copy link
Contributor

You may want to use the curl's -f flag like I did in #649, instead of checking if the response contains "message"

@bl-ue
Copy link

bl-ue commented May 29, 2021

We should close this — it's out-of-date and 4 years old, and has no votes.

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.

None yet

5 participants