Skip to content

Commit

Permalink
bug fix: create git hook not stuck anymore (now creating from file in…
Browse files Browse the repository at this point in the history
…stead of cat eof) ; pre-commit now as a symlink!
  • Loading branch information
danimesq committed Mar 15, 2024
1 parent 3c6ae1b commit 69e28dd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 51 deletions.
26 changes: 19 additions & 7 deletions .gitmeta
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
commit QmdmreDdby63wApPSNyE3jHnpMWfYstcyYemdJ3683sDeH
commit QmTyCVdDULTUKm72Qvs6Ps7F7mJcKArLU5B3N4QkfgGgeW
Branch: main

------------------------------

chown -h 1000:1000 './.gitmeta'
chmod 0755 './.gitmeta'
/usr/bin/touch -hcmd "2024-03-15 15:44:30.1444364000 -0300" './.gitmeta'
/usr/bin/touch -hcad "2024-03-15 15:18:53.5880235000 -0300" './.gitmeta'
/usr/bin/touch -hcmd "2024-03-15 15:52:57.6367678000 -0300" './.gitmeta'
/usr/bin/touch -hcad "2024-03-15 15:44:30.1844360000 -0300" './.gitmeta'
chown -h 1000:1000 './.gitmeta-cid'
chmod 0755 './.gitmeta-cid'
/usr/bin/touch -hcmd "2024-03-15 15:44:30.0764372000 -0300" './.gitmeta-cid'
/usr/bin/touch -hcad "2024-03-15 15:44:30.1404365000 -0300" './.gitmeta-cid'
/usr/bin/touch -hcmd "2024-03-15 15:52:57.5687672000 -0300" './.gitmeta-cid'
/usr/bin/touch -hcad "2024-03-15 15:52:57.6327678000 -0300" './.gitmeta-cid'
chown -h 1000:1000 './Tasks.txt'
chmod 0755 './Tasks.txt'
/usr/bin/touch -hcmd "2024-03-15 15:44:23.0245187000 -0300" './Tasks.txt'
/usr/bin/touch -hcad "2024-03-15 15:44:29.8484398000 -0300" './Tasks.txt'
/usr/bin/touch -hcmd "2024-03-15 15:52:45.7246590000 -0300" './Tasks.txt'
/usr/bin/touch -hcad "2024-03-15 15:52:52.1967177000 -0300" './Tasks.txt'
chown -h 1000:1000 './init.sh'
chmod 0755 './init.sh'
/usr/bin/touch -hcmd "2024-03-15 15:52:16.7324086000 -0300" './init.sh'
/usr/bin/touch -hcad "2024-03-15 15:52:52.2367181000 -0300" './init.sh'
chown -h 1000:1000 './install.sh'
chmod 0755 './install.sh'
/usr/bin/touch -hcmd "2024-03-15 15:50:59.7878523000 -0300" './install.sh'
/usr/bin/touch -hcad "2024-03-15 15:52:52.2367181000 -0300" './install.sh'
chown -h 1000:1000 './pre-commit'
chmod 0664 './pre-commit'
/usr/bin/touch -hcmd "2024-03-15 15:46:32.9074917000 -0300" './pre-commit'
/usr/bin/touch -hcad "2024-03-15 15:52:52.2567182000 -0300" './pre-commit'
5 changes: 4 additions & 1 deletion .gitmeta-cid
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Branch: main
Tasks.txt: QmUjVRjnMYy4frEa3ycEjnujboJ7gENYSy7c6WkpR3TeBq
Tasks.txt: QmYetV54G4TJBwoiFw7kGpXAjwoUWTKHXetXj1KsSffRqH
init.sh: QmP2onTksejZi4tTKiTmgeHwRYhucZycLAcywugVzoY5fm
install.sh: QmXWL4d8u7bPwNBnR77KLsgjJugGt7RCnB8rtnw1H6xvQj
pre-commit: QmV3C9xY6FSEZ2uh2KcuVGq1CTp2jGy5kNuZipHUnGtoRo
2 changes: 0 additions & 2 deletions Tasks.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
- bug fix: create git hook not stuck anymore (now creating from file instead of cat eof)

- show release version in .gitmeta (r3) and .gitmeta-cid (r2)
- .gitmeta: also display the current folder, as folderstamp does and as .gitmeta already does for branch
- bug fix issue of every 2nd commit modifying meta files
Expand Down
42 changes: 1 addition & 41 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,7 @@ EOF
echo "Done!"
else
echo ".git/hooks/pre-commit doesn't exist. Creating it..."
cat > .git/hooks/pre-commit <<EOF
#!/bin/bash
#01VCSHere
echo "Storing files' timestamp, CID/hash; and other files/commit's metadata..."
commit_author="$(git config user.name)"" <""$(git config user.email)"">"
commit_message=$(cat $1)
current_branch=$(git rev-parse --abbrev-ref HEAD) #from https://dev.to/anibalardid/how-to-check-commit-message-and-branch-name-with-git-hooks-without-any-new-installation-n34
# https://github.com/typicode/husky/discussions/1171
if [ ! -f ".gitmeta-cid" ]; then touch .gitmeta-cid; fi
echo "Branch: $current_branch" > .gitmeta-cid & #use ">" instead of ">>" as a way of emptying .gitmeta-cid before writing new commit data
# Get a list of all staged files
staged_files=$(git diff --cached --name-only)
# Hash (IPFS CID) the contents of each staged file, to the pipe
for file in $staged_files; do
if [ -f "$file" ]; then
file_cid=$(ipfs add -q --only-hash "$file")
echo "$file"": ""$file_cid" >> .gitmeta-cid &
fi
done
commit_cid=$(ipfs add -q --only-hash .gitmeta-cid)
echo "commit ""$commit_cid" > .gitmeta #use ">" instead of ">>" as a way of emptying .gitmeta before writing new commit data
echo "Branch: ""$current_branch" >> .gitmeta
echo "" >> .gitmeta && echo "------------------------------" >> .gitmeta && echo "" >> .gitmeta
# If the .eth file exists, sign the commit data with the Ethereum account
if [ -f ".git/hooks/.eth" ]; then
eth_account=$(cat .git/hooks/.eth)
signature=$(geth --exec "web3.personal.sign(web3.toHex('$commit_cid'), '$eth_account', null)" attach)
fi
bash .git/hooks/git-meta --store
git add .gitmeta
git add .gitmeta-cid
echo "Done. Meta has been preserved!"
EOF
ln -sf /usr/lib/01/git-meta/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "Done!"
fi
Expand Down
6 changes: 6 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if [ ! -e /usr/lib/01 ]; then sudo mkdir /usr/lib/01; fi
if [ ! -e /usr/lib/01/git-meta ]; then sudo mkdir /usr/lib/01/git-meta; fi
sudo cp -f git-meta /usr/bin/
sudo cp -f init.sh /usr/lib/01/git-meta/
sudo cp -f pre-commit /usr/lib/01/git-meta/
sudo cp -f README.md /usr/lib/01/git-meta/

#installfail(){
Expand All @@ -30,3 +31,8 @@ if [ -f /usr/lib/01/git-meta/init.sh ];then
echo "- Turning git-meta's init.sh into an executable..."
sudo chmod +x /usr/lib/01/git-meta/init.sh
fi

if [ -f /usr/lib/01/git-meta/pre-commit ];then
echo "- Turning git-meta's pre-commit into an executable..."
sudo chmod +x /usr/lib/01/git-meta/pre-commit
fi
39 changes: 39 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

#01VCSHere

echo "Storing files' timestamp, CID/hash; and other files/commit's metadata..."

commit_author="$(git config user.name)"" <""$(git config user.email)"">"
commit_message=$(cat $1)
current_branch=$(git rev-parse --abbrev-ref HEAD) #from https://dev.to/anibalardid/how-to-check-commit-message-and-branch-name-with-git-hooks-without-any-new-installation-n34
# https://github.com/typicode/husky/discussions/1171

if [ ! -f ".gitmeta-cid" ]; then touch .gitmeta-cid; fi

echo "Branch: $current_branch" > .gitmeta-cid & #use ">" instead of ">>" as a way of emptying .gitmeta-cid before writing new commit data
# Get a list of all staged files
staged_files=$(git diff --cached --name-only)
# Hash (IPFS CID) the contents of each staged file, to the pipe
for file in $staged_files; do
if [ -f "$file" ]; then
file_cid=$(ipfs add -q --only-hash "$file")
echo "$file"": ""$file_cid" >> .gitmeta-cid &
fi
done

commit_cid=$(ipfs add -q --only-hash .gitmeta-cid)
echo "commit ""$commit_cid" > .gitmeta #use ">" instead of ">>" as a way of emptying .gitmeta before writing new commit data
echo "Branch: ""$current_branch" >> .gitmeta
echo "" >> .gitmeta && echo "------------------------------" >> .gitmeta && echo "" >> .gitmeta

# If the .eth file exists, sign the commit data with the Ethereum account
if [ -f ".git/hooks/.eth" ]; then
eth_account=$(cat .git/hooks/.eth)
signature=$(geth --exec "web3.personal.sign(web3.toHex('$commit_cid'), '$eth_account', null)" attach)
fi

bash .git/hooks/git-meta --store
git add .gitmeta
git add .gitmeta-cid
echo "Done. Meta has been preserved!"

0 comments on commit 69e28dd

Please sign in to comment.