User Tools

Site Tools


programming:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
programming:git [2019/11/07 11:52] – [Exclude file from last commit] clemixprogramming:git [2019/12/09 14:21] (current) clemix
Line 17: Line 17:
 <code bash> <code bash>
 git commit -c ORIG_HEAD   git commit -c ORIG_HEAD  
 +</code>
 +====== Checkout PR from github on a new branch ======
 +<code bash>
 +#!/bin/bash +x
 +
 +pr_url="${1:?"Need 'pr_url' as parameter pointing to a github pull request or 'repo_name' (sending repo) and 'pr' variables, e.g. either 'https://github.com/os-autoinst/os-autoinst-distri-opensuse/pull/1234' 'me/os-autoinst-distri-opensuse' and '1234'"}"
 +target_repo_part=${pr_url%%/pull*}
 +pr="${pr_url##*/}"
 +pr_url=${target_repo_part/github.com/api.github.com/repos}/pulls/$pr
 +pr_content=$(curl "${AUTHENTICATED_REQUEST}" -s "$pr_url")
 +label=$(echo "$pr_content" | jq -r '.head.label') || throw_json_error "$pr_url" "$pr_content"
 +user=$(echo "$pr_content" | jq -r '.user.login') || throw_json_error "$pr_url" "$pr_content"
 +repo_name="${repo_name:-"${label%:*}/${target_repo_part##*/}"}"
 +branch="${branch:-"${label##*:}"}"
 +repo="${repo:-"https://github.com/${repo_name}.git"}"
 +
 +echo "USER:   $user"
 +echo "REPO:   $repo"
 +echo "BRANCH: $branch"
 +echo "PR:     #$pr"
 +
 +
 +echo git checkout -b "PR$pr-$user-$branch" master
 +git checkout -b "PR$pr-$user-$branch" master
 +echo git pull "$repo" "$branch"
 +git pull "$repo" "$branch"
 </code> </code>
  
  
programming/git.1573123971.txt.gz · Last modified: by clemix

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki