]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
script/ceph-backport.sh: explicitly sanity-check git remotes
authorNathan Cutler <ncutler@suse.com>
Thu, 5 Sep 2019 10:02:24 +0000 (12:02 +0200)
committerNathan Cutler <ncutler@suse.com>
Fri, 6 Sep 2019 10:47:30 +0000 (12:47 +0200)
Signed-off-by: Nathan Cutler <ncutler@suse.com>
src/script/ceph-backport.sh

index 34ec61ae8d8cb6ea589c63dae60991a47a9e6387..2384191216e19b74cf0a489c42cba0bb4f0411e8 100755 (executable)
@@ -46,9 +46,9 @@
 # determining reasonable defaults. In addition, the following two variables
 # should at least be checked against the output of "git remote -v" in your clone:
 #
-# github_repo     # The "git remote" name of your Ceph fork on GitHub;
+# fork_remote     # The "git remote" name of your Ceph fork on GitHub;
 #                 # defaults to "origin" if not set
-# ceph_repo       # The "git remote" name of the Ceph repo on GitHub;
+# upstream_remote # The "git remote" name of the upstream Ceph repo on GitHub;
 #                 # defaults to "upstream" if not set
 #
 # Without correct values for all of the above variables, this script will not
@@ -191,24 +191,34 @@ function init_mandatory_vars {
     test "$redmine_user_id" || failed_required_variable_check redmine_user_id
     test "$github_token"    || failed_required_variable_check github_token
     test "$github_user"     || failed_required_variable_check github_user
-    true "${github_repo:=origin}"
-    true "${ceph_repo:=upstream}"
+    if [ -z "$fork_remote" -a -n "$github_repo" ] ; then
+        fork_remote="$github_repo"
+    fi
+    true "${fork_remote:=origin}"
+    if [ -z "$upstream_remote" -a -n "$ceph_repo" ] ; then
+        upstream_remote="$ceph_repo"
+    fi
+    true "${upstream_remote:=upstream}"
     true "${redmine_endpoint:="https://tracker.ceph.com"}"
     true "${github_endpoint:="https://github.com/ceph/ceph"}"
     debug "Redmine user: ${redmine_user_id}"
-    debug "GitHub user:  ${github_user}"
-    debug "Fork remote:  ${github_repo}"
-    if git remote -v | egrep ^${github_repo}\\s+ ; then
+    debug "GitHub user: ${github_user}"
+    debug "Checking fork remote ->${fork_remote}<-"
+    local fork_remote_exists=$(git remote -v | egrep ^${fork_remote}\\s+)
+    if [ "$fork_remote_exists" ] ; then
         true  # remote exists; good
     else
-        error "github_repo is set to ->$github_repo<- but this remote does not exist"
+        error "git remote ->$fork_remote<- not found"
+        info "(Hint: are you setting fork_remote as described in the documentation?)"
         exit 1
     fi
-    debug "Ceph remote:  ${ceph_repo}"
-    if git remote -v | egrep ^${ceph_repo}\\s+ ; then
+    debug "Checking upstream remote ->${upstream_remote}<-"
+    local upstream_remote_exists=$(git remote -v | egrep ^${upstream_remote}\\s+)
+    if [ "$upstream_remote_exists" ]; then
         true  # remote exists; good
     else
-        error "ceph_repo is set to ->$ceph_repo<- but this remote does not exist"
+        error "git remote ->$upstream_remote<- not found"
+        info "(Hint: are you setting upstream_remote as described in the documentation?)"
         exit 1
     fi
 }
@@ -288,19 +298,19 @@ function prepare {
     fi
     info "Found $number commits in ${original_pr_url}"
 
-    debug "Fetching latest commits from $ceph_repo"
-    git fetch $ceph_repo
+    debug "Fetching latest commits from $upstream_remote"
+    git fetch $upstream_remote
 
     debug "Initializing local branch $local_branch to $milestone"
     if git show-ref --verify --quiet refs/heads/$local_branch ; then
         error "Cannot initialize $local_branch - local branch already exists"
         exit 1
     else
-        git checkout $ceph_repo/$milestone -b $local_branch
+        git checkout $upstream_remote/$milestone -b $local_branch
     fi
 
     debug "Fetching latest commits from ${original_pr_url}"
-    git fetch $ceph_repo pull/$original_pr/head:pr-$original_pr
+    git fetch $upstream_remote pull/$original_pr/head:pr-$original_pr
 
     info "Attempting to cherry pick $number commits from ${original_pr_url} into local branch $local_branch"
     let offset=$number-1 || true # don't fail on set -e when result is 0
@@ -477,8 +487,8 @@ fi
 # at this point, local branch exists and is assumed to contain cherry-pick(s)
 #
 
-debug "Pushing local branch $local_branch to remote $github_repo"
-git push -u $github_repo $local_branch
+debug "Pushing local branch $local_branch to remote $fork_remote"
+git push -u $fork_remote $local_branch
 
 original_issue=""
 original_pr=""