summaryrefslogtreecommitdiff
path: root/pbs-package-fork
blob: 97aeec916bdb8d0b9a53ff237a31b1f311b7c96f (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 -euE

. pbs-plumb-shlib

cmd=${0##*/}
usage() {
	echo "Usage: $cmd [OPTIONS] REPOSITORY OLDPACKAGE REPO/NEWPACKAGE"
	echo 'Forks a package.'
	echo ''
	echo 'To fork a local package, (for example, making `pcr/emacs-lucid`'
	echo 'from `pcr/emacs-lucid`), the repository is the local filesystem,'
	echo 'so use `./`'
	echo ''
	echo '    $cmd ./ emacs pcr/emacs-lucid'
	echo ''
	echo 'This forks the branch `packages/emacs` into a new branch'
	echo '`packages/emacs-lucid`, creates the file `pbstrack` in it, and'
	echo 'checks it out as a git submodule to the directory '
	echo '`prc/emacs-lucid`.'
	echo ''
	echo 'Use `pbs-merge` to pull updates from the original package.'
	echo ''
	echo 'Options:'
	echo '  -h            Show this message'
}

main() {
	while getopts 'h' arg; do
		case $arg in
			h) usage; return 0;;
			*) usage; return 1;;
		esac
	done
	shift $(($OPTIND - 1))
	if [[ $# != 3 ]]; then
		usage
		return 1
	fi

	local repository=$1
	local oldpackage=$2
	local dest=$3
	local newpackage="${dest##*/}"

	cdto_pbs-root

	git submodule add -b "packages/${oldpackage}" "${repository}" "${dest}"
	cd "${dest}"
	git checkout -b "packages/${newpackage}"
	echo "${repository} packages/${oldpkackage}" > pbstrack
	git add pbstrack
	git commit -m "Fork package from ${repository} ${oldpackage} to ${dest}"
}

main "$@"