summaryrefslogtreecommitdiff
path: root/sh/ccp
blob: 66175d7b8f99f3ef4ab5219b81832375104550c2 (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
56
57
58
59
60
61
62
#!/bin/sh
# Cfg git Cherry Pick interactive helper

ssh pp 'gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type nothing'

cd "$HOME/programs/config_local_arch" || exit
all_branch="$(git branch | awk '{print ($1=="*")?$2:$1}')"
all_branch_no_master="$(echo "$all_branch" | grep -v master)"

# https://www.shellcheck.net/wiki/SC2095
# ssh may swallow stdin, use read need file descriptor workaround or ssh disable stdin
# so I choose to use for instead of `... | while read ...`
for branch in $all_branch; do
	if [ "$branch" != master ]; then
		echo "sshing to server $branch..."
		# note need \$ else it will run cfg on current computer instead of remote server
		ssh -t "$branch" "[ \"\$(cfg -l rev-list origin/$branch..HEAD)\" ] && cfg -l push"
	fi
	git checkout "$branch"
	git pull
done

< "$XDG_DATA_HOME/mydata/cfgl_cherry_picked" read -r picked
# need checkout to master branch to list new master branch commits
git checkout master
for commit in $(git rev-list --reverse "$picked..HEAD"); do
	git show "$commit"
	printf 'Enter branch names to cherry pick this commit:
(a for all, space to separate multiple branches, enter to skip)\n'
	read -r branch_pick
	if [ "$branch_pick" = a ]; then 
		branch_pick="$all_branch_no_master"
	fi
	for branch in $branch_pick; do
		# Mostly due to cherry-pick error. It seems if cherry-pick passed,
		# checkout will work. It is easier to check checkout error here and do
		# a while loop here to make sure cherry-pick works, instead of check
		# cherry-pick error.
		while ! git checkout "$branch"; do
			echo 'checkout error, fix and enter to continue'
			read a
		done
		git cherry-pick "$commit"
		git status
	done
done

cp "$XDG_DATA_HOME/mydata/cfgl_cherry_picked" "$XDG_DATA_HOME/mydata/cfgl_cherry_picked.bak"
while ! git checkout master; do
	echo 'checkout error, fix and enter to continue'
	read a
done
git rev-parse HEAD > "$XDG_DATA_HOME/mydata/cfgl_cherry_picked"

for branch in $all_branch_no_master; do
	git checkout "$branch"
	git push
	echo "sshing to server $branch..."
	ssh -t "$branch" 'cfg -l pull; cfg -lM; cfg -l status'
done

ssh pp 'gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type suspend'