Preamble:
When committing I tend to format message as following:
[<task number>] <task title>
which should be converted by pre-push hook to a valid GitHub syntax as following:
Work item [[<git_branch>](http://tracker/_workitems/<git_branch>)]:
- [x] [[<task_number>](http://tracker/_workitems/<task_number>)] <task title>
and then it's cat
ted to console output so i can copy-paste it to PR description on github.
Task
Go one step further and put that message into clipboard so that I don't have to manually select it and copy from console.
Since I'm on Linux machine I decided that I'll use xclip
for the task.
My current git hook script looks as following:
#!/bin/sh
PBI=\`git symbolic-ref --short HEAD\`
echo "**Backlog Item [$PBI]:**\n" > pr_messages/$PBI.md
git log develop..HEAD --format=" - [x] %B" >> pr_messages/$PBI.md
sed -r -i 's|\[([0-9]{4,})\]|[[\1](http://tracker/_workitems/\1)]|g' pr_messages/$PBI.md
cat pr_messages/$PBI.md
Problem
When I add following line to the end of this script
cat pr_messages/$PBI.md | xclip -selection clipboard
I get the message in my Ctrl+C/V clipboard, but git hangs and I have to abort it. Given that it's supposed to be a pre-push hook, it effectively prevents me from actually pushing my code.
UPD: As proposed by @wumpus-q-wumbley here's the strace output:
$> ps aux | grep git
kraplax 29796 0.0 0.0 25696 5660 pts/1 S+ 12:55 0:00 git push
kraplax 29797 0.0 0.0 48276 3040 pts/1 S+ 12:55 0:00 ssh git@github.com git-receive-pack 'eduard-sukharev/ProFIT.git'
$> sudo strace -p 29796
Process 29796 attached
wait4(29797,
^CProcess 29796 detached
<detached ...>
$> sudo strace -p 29797
Process 29797 attached
select(7, [3 4], [], NULL, NULL
^CProcess 29797 detached
<detached ...>
Which essentially shows that git-push is waiting for the ssh process ssh git@github.com git-receive-pack 'eduard-sukharev/ProFIT.git'
which hangs. This all shifts the focus of the problem a bit.
UPD2: Setting GIT_TRACE=~/git_trace.log
gives this info:
$ cat ../git_trace.log
trace: built-in: git 'rev-parse' '--abbrev-ref' 'HEAD'
trace: built-in: git 'rev-parse' '--abbrev-ref' 'HEAD'
trace: built-in: git 'status' '--porcelain'
trace: built-in: git 'push'
trace: run_command: 'ssh' 'git@github.com' 'git-receive-pack '\''eduard-sukharev/ProFIT.git'\'''
trace: run_command: '.git/hooks/pre-push' 'origin' 'git@github.com:eduard-sukharev/ProFIT.git'
trace: built-in: git 'symbolic-ref' '--short' 'HEAD'
trace: built-in: git 'log' 'develop..HEAD' '--format= - [x] %B'
trace: built-in: git 'rev-parse' '--abbrev-ref' 'HEAD'
trace: built-in: git 'status' '--porcelain'
Question
Why does this process hang if otherwise it doesn't?
How should I rewrite that line to complete intended task?
Should I probably use other tool for managing clipboard, other than xclip
?