I'm currently trying to run a script in a repo in the master branch
.
I want the output of that script (html file) to go into another branch called output-branch
.
Is there a command that let's me do this?
I'm currently trying to run a script in a repo in the master branch
.
I want the output of that script (html file) to go into another branch called output-branch
.
Is there a command that let's me do this?
Write just:
git checkout output-branch
in the script, before generate the html-file.
Git's convenience commands are built around the usual single-user single-checkout workflow.
Its core commands are ... not so constrained. What you're asking for is easy.
outputid=$(myscript | git hash-object -w --stdin)
treeid=$(echo 100644 blob $outputid$'\t'script-output | git mktree)
branchnow=$(git rev-parse -q --verify output-branch)
git update-ref refs/heads/output-branch $(
git commit-tree ${branchnow:+-p $branchnow} -m 'script output' $treeid
)
The first line is "add the myscript
output to the repo and save its id".
The second is "make a directory path to that added content and save that directory's id"
The third is "check whether there's already a history"
The fourth and rest notably use the :+
expansion modifier, check the variable and if there's anything in it expand to what I give here, so ${branchnow:+-p $branchnow}
expands to nothing if there's no existing branch history, or -p $branchnow
if there's already history. The commit-tree
and update-ref
do exactly what it looks like they do: return an id for a newly-created commit of the snapshot you just built, and (re-)hang the output-branch
branch tip label on that commit.
You can run the script by getting the content of it with curl -sfL
command on the fly and then run it by the executor. First, you need the raw format of the file by finding the file on Github or whatever and then click the raw
view button on the page.
See the following example for bash script:
bash -l -c "$(curl -sfL https://raw.githubusercontent.com/bitrise-tools/codesigndoc/master/_scripts/install_wrap.sh)"