0

I am having a shell script basically whenever a user is making any changes in git file travis will start running and in Travis YAML file I have specified shell script path and shell script basically compare my current_working_branch with remote push branch.

I am using the below command to get the change file and running Pylint on the changed file.

all_changed_files=$(git diff-tree --name-only -r --no-commit-id --line-prefix=$(git rev-parse --show-toplevel)/ $TRAVIS_BRANCH origin/main | grep '\.py'$)

So in the above command origin/main is fixed and working fine I am getting problems when I am trying to push changes from $TRAVIS_BRANCH (current local branch) to a new branch let us say origin/ABC (git push -u origin ABC)

So is there any way to get the details of what branch a user is pushing so that I will use it in my script file. (I have checked the Travis CI document but no luck)?

torek
  • 448,244
  • 59
  • 642
  • 775
Shailesh Yadav
  • 301
  • 2
  • 16
  • Is it really appropriate to run tests on every push on every branch? I often use a branch to save wild ideas that are not necessarily "intact". – Tim Roberts Sep 06 '22 at 17:31
  • I don't think you will find that in the information of the push trigger of a CI builder. You may have your travis job store somewhere (anywhere: a file that can be shared between runners ? a database server ? a git repository to which you push refs ?) the last hash it tested for each branch "foo". If no previous hash is found fall back on origin/main. – LeGEC Sep 06 '22 at 17:59
  • side note : `git diff --name-only -- "**.py"` is a simpler command that should give you the list of files you want. You may add the `git rev-parse --show-toplevel` prefix in a separate step, or simply cd into the root of the repository and use the relative paths provided by `git diff --name-only ...` – LeGEC Sep 06 '22 at 18:07
  • This isn't up to Git, it's up to the CI system (in this case Travis). But in general, be wary of depending on a branch name: use a commit hash ID if at all possible. By the time you get hold of a branch name *in* a CI script, it could be "wrong" for your purposes (having been updated yet again). – torek Sep 06 '22 at 19:16

0 Answers0