Jump to content
JanReimer

before-checkin trigger: Analyze file contents

Recommended Posts

Hi folks,

we want to establish before-checkin trigger that check file contents (in this case, some file types must have linux line endings). As far as I understand the triggers guide we must use client side triggers because the server side trigger is not able to access the file contents (there is no changeset yet in before-checkin). Is this correct?

Best regards
Jan

Share this post


Link to post
Share on other sites

Hi @JanReimer,

you are right. If you use the server side trigger you will not be able to access the file content before the checkin operation takes place, notice you will be able to do it with a server side "after-checkin" trigger but in your case it will be useless.

It's better if you create a client side trigger and you check if the name of the files are ok and it's content as well.

You can solve the deploy of the trigger by using a "Trigger variable" in order to customize the trigger path: https://www.plasticscm.com/documentation/triggers/plastic-scm-version-control-triggers-guide.shtml#C4_Comunication_Client

If you have any questions please don't hesitate to contact us.

 

 

Share this post


Link to post
Share on other sites

Hi,

has something changed in the meantime? Triggers documentation (https://www.plasticscm.com/documentation/triggers/plastic-scm-version-control-triggers-guide#Checkin)  says 

Quote

"Some examples of usages: checking code before it is checked in on the repository against some validation"

and first example https://www.plasticscm.com/documentation/triggers/plastic-scm-version-control-triggers-guide#Chapter6:Samples demonstrates how to format code in a before-checkin trigger, however, I am unable to get file content in a before-checkin trigger.  Item specification contains only server path and changeset number and I don't know how to refer to a file being checked in.

Best regards

BK

Share this post


Link to post
Share on other sites

Hello.

You need to read standat input. If you take a look into the trigger you are refering, it uses the standar inout where you can get the file path. And the the trigger runs the following command to extract the revision content from the repository:

# extract revision content from repository to temp file
    res = system("cm cat #{revspec} --file=\"#{tmpfile}\"")

Regards,

Carlos.

 

Share this post


Link to post
Share on other sites

I read from the standard input, but I can't figure out how to get a new file content. 
Let me give you an example:

PS C:\workspaces\plastic-triggers\testy> cm status
cs:43@plastic-triggers@plasticscm.iw.hsi.pl:8087 (head)
PS C:\workspaces\plastic-triggers\testy> echo 'cs:43 -> cs:44' >  .\test.txt
PS C:\workspaces\plastic-triggers\testy> cm co .\test.txt
The selected items are about to be checked out. Please wait ...
Item c:\workspaces\plastic-triggers\testy\test.txt was correctly checked out
PS C:\workspaces\plastic-triggers\testy> cm ci .\test.txt -m 'test'
The selected items are about to be checked in. Please wait ...
- Checkin finished 34 bytes/34 bytes [##################################] 100 %
Modified c:\workspaces\plastic-triggers\testy\test.txt
Created changeset cs:44@br:/main@plastic-triggers@plasticscm.iw.hsi.pl:8087 (mount:'/')

Trigger is set

PS C:\workspaces\plastic-triggers\testy> cm ltr |findstr before
1 codestyle       /triggers/plastic-triggers/before-checkin-plastic-triggers.sh b.kot      before-checkin rep:plastic-triggers,*

Triggers content:

#!/bin/bash

echo "" > /triggers/stdin_before.txt
while IFS='$\n' read -r line; do
   
 echo "$line" >> /triggers/stdin_before.txt
 if [[ $line == *"FILE#"* ]]; then
  IFS=';' read -ra splitted <<< "$line"
  echo "split[0] ${splitted[0]}" >> /triggers/stdin_before.txt
  echo "split[1] ${splitted[1]}" >> /triggers/stdin_before.txt

 fi
done
exit 0

Content of a file /triggers/stdin_before.txt


CH "/" DIR#br:/main;changeset:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087
CH "/testy" DIR#br:/main;changeset:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087
CH "/testy/test.txt" FILE#br:/main;changeset:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087
split[0] CH "/testy/test.txt" FILE#br:/main
split[1] changeset:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087

The following command.

root@ec0d7edfcb97:/# cm cat "serverpath:/testy/test.txt#cs:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087"
cs:37 -> cs:43

get content of cs:43.  All I can get is a file content before modification.  My stdin doesn't match input assumed in the example,  "changeset:43@rep:plastic-triggers@repserver:ec0d7edfcb97:8087" is not a valid object specification for cm cat. 

What am I doing wrong?

Best regards

BK

Share this post


Link to post
Share on other sites

Hi,

You are right. The "cm cat" (the command used by the sample trigger in the guide) with download the content of a specificed file revision, but the revision should be already available in the database. You won't be able to do it with a before-checkin server side trigger. 

I'm guessing if a "before-clientcheckin" trigger (client side trigger) may help instead. The standar input should provide the path and you can get the full file path by appending the local workspace path.

NOTE: The trigger input provides file paths but not file content.

Regards,

Carlos.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...