summaryrefslogtreecommitdiffstats
path: root/bin/dfmk
blob: 4a87feb6be5ef2ae161486e82f97c8f705b81a5a (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
#!/bin/sh

REPO_FMT='ssh://git@git.pehjota.net/dotfiles/%s.git'

if [ ${#} -eq 0 ]; then
	printf 'Usage: %s repository ...\n' "${0}" >&2
	exit 1
fi

for repo in "${@}"; do
	if ! [ "x$(vcsh "${repo}" status --porcelain | wc -l)" = 'x0' ]; then
		printf 'Error: Repository %s has uncommited changes\n' "${repo}"
		continue
	fi

	# Initialize repository
	vcsh init "${repo}"
	vcsh "${repo}" remote add origin "$(printf "${REPO_FMT}" "${repo}")"

	# Add repository to mr.git
	cat >"${HOME}/.config/mr/available.d/${repo}.vcsh" <<-EOF
		[\$HOME/.config/vcsh/repo.d/${repo}.git]
		checkout = vcsh clone $(printf "${REPO_FMT}" "${repo}") ${repo}
		EOF
	vcsh mr add "${HOME}/.config/mr/available.d/${repo}.vcsh"
	vcsh mr commit -m "${repo}: New repository"
done