blob: 80b3251467616ec2351f657f7bba25eeb1cebbac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/bash
# Copyright (C) 2015-2022 Miquel Sabaté Solà <mikisabate@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
# This script adds the `fork` subcommand to git. This subcommand helps to keep
# a forked project updated with upstream. So, in a forked repository you would
# do:
#
# $ git fork
#
# The previous command will fetch the upstream remote and merge the master
# branch. You can change the remote and the branch to be picked like this:
#
# $ git fork branch
# $ git fork remote branch
#
# Finally, if the given remote does not exist, the user will be prompted to
# provide the URL to the remote, so it can be created.
# Configurable values: the name of the branch to be picked and the name of the
# upstream remote.
branch='master'
upstream='upstream'
if [ ! -z "$1" ]; then
upstream="$1"
fi
if [ ! -z "$2" ]; then
branch="$2"
fi
# Check whether the given upstream remote really exists. If it doesn't it will
# ask the user for a remote URL.
if [[ $(git remote show | xargs -0 | grep -Fxq "$upstream") -eq 1 ]]; then
echo "The given upstream '$upstream' remote does not exist"
echo -n "Provide one: "
read -ra url
git remote add $upstream $url
fi
git fetch $upstream && git merge $upstream/$branch
|