3 # Script for easily updating your fork of the main WRF repository
5 # Author: Michael Kavulich, September 2016
6 # No rights reserved, this script may be used, copied, or modified for any purpose
9 # 1. Clone your fork of the repository (if you already have a local clone of your fork this is optional)
10 # git clone https://your_username@github.com/your_username/WRF.git
11 # 2. Enter the directory of the local clone of your fork
13 # 3. Run this script from within the directory structure of your local clone of your fork
15 # You will be asked to enter your Github username: enter it and hit "return".
16 # 4. If all went well, you should see one of two different messages at the end:
17 # - If your fork is already up-to-date, you should see "Already up-to-date."
18 # - If your fork is not up-to-date, this script initiates a fast-forward merge to bring your fork up-to-date with the
19 # develop of the main repository (https://github.com/wrf-model/WRF). Near the end git will print a line of statistics
20 # describing what changed, which will look something like this:
21 # 19 files changed, 27 insertions(+), 27 deletions(-)
22 # followed by a few more lines and this final message:
23 # Branch develop set up to track remote branch develop from origin.
26 # - This is a preliminary version of what will hopefully be a more detailed script in the future. This one only performs fast-forward merges.
33 # First off: check if we are on develop, and quit if we are not. We want the branch switch to be transparent to users
34 my $curr_branch = `git rev-parse --abbrev-ref HEAD`;
36 die "\nERROR ERROR ERROR:\nYou are currently on the branch $curr_branch\n\nThis script must be run from the develop branch.\n\nCheck out the develop branch, then run this script, then check out your working branch $curr_branch when the update is finished\n\n" unless $curr_branch eq "develop";
39 # Prompt user for their username
40 print "Please enter your Github username:\n";
41 while ($go_on eq "") {
45 print "Please enter your Github username:\n";
51 print "Username = $username\n";
52 my $main_repo = "https://$username\@github.com/wrf-model/WRF.git";
53 my $fork = "https://$username\@github.com/$username/WRF.git";
55 # Set main repository as a remote repository named "upstream", per standard git conventions
56 print "\nStep 1: Setting main repository as a remote repository named 'upstream'\n\n";
57 ! system("git", "remote", "rm", "upstream") or warn "If you see \"error: Could not remove config section 'remote.upstream'\" this is normal! Don't panic!\n";
58 ! system("git", "remote", "add", "upstream", $main_repo) or die "Can not add main repository '$main_repo' for merging: $!\n";
60 # Set the "push" url for "upstream" to be the user's fork, to avoid accidentally pushing to the main repository
61 print "\nStep 2: Setting the 'push' url for 'upstream' to the user's fork, to avoid accidentally pushing to the main repository\n\n";
62 ! system("git", "remote", "set-url", "--push", "upstream", $fork) or die "Can not add set push repository '$fork': $!\n";
64 # Checkout develop, fetch "upstream" commits, and perform a fastforward merge
65 print "\nStep 3: Fetching 'upstream' commits, and performing fastforward merge\n\n";
66 ! system("git", "fetch", "upstream", "develop") or die "Can not fetch upstream changes from : $!\nSomething has gone seriously wrong! Perhaps you don't have internet access?\n";
67 ! system("git", "merge", "--ff-only", "upstream/develop") or die "\nCan not perform fastforward merge from upstream/develop: $!\n\nTroubleshooting info:\n\n 1. If you receive a message 'fatal: 'upstream/develop' does not point to a commit', your git version may be too old. On yellowstone, try `module load git`\n 2. If you receive a message' fatal: Not possible to fast-forward, aborting.', you have likely made local changes to the develop branch of your fork. All work should be done on branches of your fork, not the develop!\n";
69 # Finally, push updated develop to the Github copy of your fork:
70 print "\nStep 4: Pushing updated develop to fork\n\n";
71 ! system("git", "push", "-u", "origin", "develop") or die "\nCan not push updates to origin/develop : $!\n";