diff --git a/README.md b/README.md index 6bc8e68..2d76c50 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,11 @@ receiver script run any other script on the server. #### Handling submodules Submodules are not included when you do a `git push`, if you want them to be part of your workflow, have a look at [Handling Submodules](https://github.com/progrium/gitreceive/wiki/TipsAndTricks#handling-submodules). +#### Handling new repository creation + +If you want to perform some tests when a new repository is to be made, or +do some action afterwards, have a look at [Handling new repository creation](https://github.com/progrium/gitreceive/wiki/TipsAndTricks#handling-new-repository-creation) + ## So what? You can use `gitreceive` not only to trigger code on `git push`, but to provide diff --git a/gitreceive b/gitreceive index ad451d3..18c4faa 100755 --- a/gitreceive +++ b/gitreceive @@ -42,6 +42,26 @@ EOF chown "$git_user" "$receiver_path" } +# Creates the default newrepo script. This is the script that is triggered when a new repository is to be created. +setup_newrepo_script() { + declare home_dir="$1" git_user="$2" + local newrepo_path="$home_dir/newrepo" + cat > "$newrepo_path" < /dev/null - cd - > /dev/null - fi +ensure_repo_exists() { + declare repo_path="$1" repo_name="$2" username="$3" fingerprint="$4" home_dir="$5" + # Do nothing if the repo already exists + [ -d "$repo_path" ] && return + # Call the newrepo script; abort if the return code is non-null + # stdout to /dev/null to avoid `protocol error: bad line length character` + "$home_dir/newrepo" "$repo_path" "$repo_name" "$username" "$fingerprint" > /dev/null|| exit $? + [ -d "$repo_path" ] || exit 1 # make sure we created a repo } # Create a Git pre-receive hook in a git repo that runs `gitreceive hook' when the repo receives a new git push @@ -136,6 +156,8 @@ main() { setup_git_user "$GITHOME" "$GITUSER" setup_receiver_script "$GITHOME" "$GITUSER" echo "Created receiver script in $GITHOME for user '$GITUSER'." + setup_newrepo_script "$GITHOME" "$GITUSER" + echo "Created newrepo script in $GITHOME for user '$GITUSER'." ;; upload-key) # sudo gitreceive upload-key @@ -154,7 +176,7 @@ main() { export RECEIVE_FINGERPRINT="$fingerprint" export RECEIVE_REPO="$(echo "$SSH_ORIGINAL_COMMAND" | parse_repo_from_ssh_command)" local repo_path="$GITHOME/$RECEIVE_REPO" - ensure_bare_repo "$repo_path" + ensure_repo_exists "$repo_path" "$RECEIVE_REPO" "$RECEIVE_USER" "$RECEIVE_FINGERPRINT" "$GITHOME" ensure_prereceive_hook "$repo_path" "$GITHOME" "$SELF" cd "$GITHOME" # $SSH_ORIGINAL_COMMAND is set by `sshd'. It stores the originally intended command to be run by `git push'. In