Skip to content

Commit

Permalink
Added GitHub.com support.
Browse files Browse the repository at this point in the history
  • Loading branch information
waynegramlich committed Mar 30, 2020
1 parent fba580c commit efab74d
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
README.html
.remote_fork_created
77 changes: 71 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ There are 3 broad steps:
# Now "clone" the `hbrc_ros_robot_platform` repository using `git`:
# This will probably prompt for your root password...
# Type in your root password if when asked..
git clone https://github.com/hbrobotics/hbrc_ros_robot_platform.git
git clone -o upstream https://github.com/hbrobotics/hbrc_ros_robot_platform.git
# Change the current working directory to the root of the cloned repository
cd hbrc_ros_robot_platform

Expand Down Expand Up @@ -643,12 +643,11 @@ Write:
* fork-push:
* fork-pull-request:

https://stackoverflow.com/questions/14821583/pull-request-without-forking
* https://stackoverflow.com/questions/14821583/pull-request-without-forking

You still need that one-liner:

You still need that one-liner:

hub fork; git push -u $GIT_USER HEAD; hub pull-request
hub fork; git push -u $GIT_USER HEAD; hub pull-request

https://andrewlock.net/creating-github-pull-requests-from-the-command-line-with-hub/

Expand All @@ -663,7 +662,7 @@ Reasonable description of what is going on:
Githubs documentation about forking a repo:
https://help.github.com/en/github/getting-started-with-github/fork-a-repo

An alternative to the hub CLI command:
An alternative to the hub CLI command (documentation is weak and I could not get it to work.)
https://medium.com/mergify/managing-your-github-pull-request-from-the-command-line-89cb6af0a7fa

git clone -o upstream URL
Expand All @@ -687,3 +686,69 @@ Concept:

* Asymetric push and pull:
https://stackoverflow.com/questions/2916845/different-default-remote-tracking-branch-for-git-pull-and-git-push

* `git remote add --help`:
provides useful information.

* `git remote add [options...] REMOTE_NAME REMOTE_URL`:
* -t BRANCHNAME : track only BRANCHNAME ; can be specified multiple times for multiple branches
* -m MASTERNAME : symbol-ref to refs/remotes/MASTERNAME/HEAD (see set-head command)
* `git remote set-head REMOTE_NAME --auto|--delete BRANCH`:
* `git set-url ...`:
* Appears to default to modifying the fetch behavior. Specify --push
* `git set-url --push REMOTE_NAME REMOTE_URL`: Sets push behavior
* `git set-url REMOTE_NAME REMOTE_URL`: Sets fetch behavior
Note that REMOTE_URL must be the same for both push and fetch behavior.
* `git remote set-head REMOTE_NAME DEFAULT_BRANCH : Makes it so you do not have to
always specify the branch name:

It looks like we want to say:

# This creates a new remote named `upstream` that is tracking the
# github.com:hbrobotics/hbrc_ros_robot_platform repository using the "git"
# protocol, (which is basically ssh). This can be done with the orginal
# -o option in the origin git clone:
git remote add upstream [email protected]:hbrobotics/hbrc_ros_robot_platform
# Next we want to disallow pushes to the `upstream` remote:
# https://stackoverflow.com/questions/7556155/git-set-up-a-fetch-only-remote
git remote set-url --push upstream no-pushing-to-upstream-url-is-allowed
# Next we want to set the `upstream` head to default to master:
git remote set-head upstream master

# git remote -v should list
# upstream [email protected]:hbrobotics/hbrc_ros_robot_platform (fetch)a
# upstream no-pushing-to-upstream-url-is-allowed (push)


https://stackoverflow.com/questions/40462111/git-prevent-commits-in-master-branch
Next, to configure master branch to disallow commits, create `file .git/hooks/pre-commit`
with following content:


#!/bin/sh

branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "master" ]; then
echo "You can't commit directly to master branch"
exit 1
fi

Do a chmod +x of the file to make it executable.

Now figure out how to create the staging remote. The hub(1) command wants the
staging remote named to be `github` or `origin`.

# Create a staging remote:
git remote add upstream [email protected]:$GITHUB_ACCOUNT_NAME/hbrc_ros_robot_platform

We need to figure out how to do the `hub fork` once:

hub fork --remote-name github --org $GITHUB_ACCOUNT_NAME

hub fork; git push -u $GIT_USER HEAD; hub pull-request



66 changes: 66 additions & 0 deletions install_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,69 @@ else
echo "hr2 Python virtual environment already exists."
fi

# Install `hub` program for interfacing with GitHub.Com:
if [ -z `which hub` ]
then
echo "**************** Installing hub program to interface with GitHub.Com ..."
sudo snap install hub --classic
else
echo "hub program was previously installed."
fi

# Make sure that `upstream` remote exists:
if [ `git remote -v | grep -c upstream` == "0" ]
then
echo "**************** Installing upstream remote for get ..."
git remote add upstream [email protected]:hbrobotics/hbrc_ros_robot_platform
git remote set-head upstream master
else
echo "Remote named upstream exists for get."
fi

# Make sure that no pushing to upstream is occurs:
if [ `git remote -v | grep -c no-pushing-to_upstream-remote-is_allowed` == "0" ]
then
echo "**************** Ensuring that nothing can be pushed to upstream remote ..."
git remote set-url --push upstream no-pushing-to-upstream-remote-is-allowed
# Next we want to set the `upstream` head to default to `master`:
echo "here 1"
git remote set-head upstream master
else
echo "Nothing can be pushed to upstream remote."
fi

# Make sure that the master branch disallows commits to the master branch.
PRE_COMMIT=.git/hooks/pre-commit
if [ ! -x $PRE_COMMIT ]
then
echo "**************** Ensure that commits can not be performed on the master branch ..."
# This is a more that a little kludgy:
echo '#!/bin/sh' > $PRE_COMMIT
echo 'branch="$(git rev-parse --abbrev-ref HEAD)"' >> $PRE_COMMIT
echo 'if [ "$branch" = "master" ]; then' >> $PRE_COMMIT
echo ' echo "You can not commit directly to master branch"' >> $PRE_COMMIT
echo ' exit 1' >> $PRE_COMMIT
echo 'fi' >> $PRE_COMMIT
chmod +x $PRE_COMMIT
else
echo "Commits can not be performed on the master branch."
fi

# Create the remote fork:
REMOTE_FORK_CREATED=.remote_fork_created
if [ -n "$GITHUB_ACCOUNT_NAME" ]
then
if [ ! -f $REMOTE_FORK_CREATED ]
then
echo "**************** Creating forked project repository fork on GigHub.Com ..."
hub fork --remote-name github --org $GITHUB_ACCOUNT_NAME
touch $REMOTE_FORK_CREATED
git remote set-url upstream no-pulling-from-github-remote-is-allowed
else
echo "Forked project repository already created on GitHub.Com."
fi
else
echo '!!!!!!!!!!!!!!!! No fork project repository until GITHUB_ACCOUT_NAME specfied in ~/.bshrc'
echo '!!!!!!!!!!!!!!!! Example: export GITHUB_ACCOUNT_NAME=... # Replace ... with account name'
echo '!!!!!!!!!!!!!!!! Follow by typing source ~/.bashrc'
fi

0 comments on commit efab74d

Please sign in to comment.