Apr 202022
 

I need some help with the git processing shell script.

Look at line 82 in this script please. See those hardcoded branch names? That’s my problem.

Let’s reduce the shell script to a simple proof of concept.

% cat ~/tmp/poc.sh
#!/bin/sh

  git for-each-ref --format '%(objecttype) %(refname)' \
      | sed -n 's/^commit refs\/remotes\///p' \
      | while read -r refname
   do
     echo "working on '$refname'"
   done

When run from the root directory of a FreeBSD ports checkout, you should see this:

[dev-ingress01 dan ~ingress/repos/ports] % ~/tmp/poc.sh
working on 'origin/2014Q1'
working on 'origin/2014Q2'
working on 'origin/2014Q3'
working on 'origin/2014Q4'
working on 'origin/2015Q1'
working on 'origin/2015Q2'
working on 'origin/2015Q3'
working on 'origin/2015Q4'
working on 'origin/2016Q1'
working on 'origin/2016Q2'
working on 'origin/2016Q3'
working on 'origin/2016Q4'
working on 'origin/2017Q1'
working on 'origin/2017Q2'
working on 'origin/2017Q3'
working on 'origin/2017Q4'
working on 'origin/2018Q1'
working on 'origin/2018Q2'
working on 'origin/2018Q3'
working on 'origin/2018Q4'
working on 'origin/2019Q1'
working on 'origin/2019Q2'
working on 'origin/2019Q3'
working on 'origin/2019Q4'
working on 'origin/2020Q1'
working on 'origin/2020Q2'
working on 'origin/2020Q3'
working on 'origin/2020Q4'
working on 'origin/2021Q1'
working on 'origin/2021Q2'
working on 'origin/2021Q3'
working on 'origin/2021Q4'
working on 'origin/2022Q1'
working on 'origin/2022Q2'
working on 'origin/HEAD'
working on 'origin/main'
[dev-ingress01 dan ~ingress/repos/ports] % 

The issue to be solved: process only those branches which use git.

The first git branch was 2021Q2 – commits prior to that branch were imported into FreshPorts via subversion.

My request to you: modify the script so that prior branches are not processed.

Using something like what you see in the code please, reproduced here:

      if [ "$refname" != "origin/2021Q2" ] && [ "$refname" != "origin/2021Q3" ] && [ "$refname" != "$MAIN_BRANCH" ]

Thank you.

EDIT 2022-04-23

Following on from Allan Jude’s suggestion to eliminate the use of sed, I liked this code:

[dev-ingress01 dan ~ingress/repos/ports] % cat ~/tmp/poc-no-sed.sh                                                                                               14:38:14
#!/bin/sh

git for-each-ref --format '%(objecttype) %(refname:lstrip=2)' refs/remotes/ --sort=-refname | 
  while read -r objtype refname
  do
#     year=${${refname#origin/}%Q*}
     quarter=${refname#origin/????Q} 
     echo "working on '$refname' - $year - $quarter"
   done
[dev-ingress01 dan ~ingress/repos/ports] % ~/tmp/poc-no-sed.sh                                                                                                   14:39:15
working on 'origin/main' -  - origin/main
working on 'origin/HEAD' -  - origin/HEAD
working on 'origin/2022Q2' -  - 2
working on 'origin/2022Q1' -  - 1
working on 'origin/2021Q4' -  - 4
working on 'origin/2021Q3' -  - 3
working on 'origin/2021Q2' -  - 2
working on 'origin/2021Q1' -  - 1
working on 'origin/2020Q4' -  - 4
working on 'origin/2020Q3' -  - 3
working on 'origin/2020Q2' -  - 2
working on 'origin/2020Q1' -  - 1
working on 'origin/2019Q4' -  - 4
working on 'origin/2019Q3' -  - 3
working on 'origin/2019Q2' -  - 2
working on 'origin/2019Q1' -  - 1
working on 'origin/2018Q4' -  - 4
working on 'origin/2018Q3' -  - 3
working on 'origin/2018Q2' -  - 2
working on 'origin/2018Q1' -  - 1
working on 'origin/2017Q4' -  - 4
working on 'origin/2017Q3' -  - 3
working on 'origin/2017Q2' -  - 2
working on 'origin/2017Q1' -  - 1
working on 'origin/2016Q4' -  - 4
working on 'origin/2016Q3' -  - 3
working on 'origin/2016Q2' -  - 2
working on 'origin/2016Q1' -  - 1
working on 'origin/2015Q4' -  - 4
working on 'origin/2015Q3' -  - 3
working on 'origin/2015Q2' -  - 2
working on 'origin/2015Q1' -  - 1
working on 'origin/2014Q4' -  - 4
working on 'origin/2014Q3' -  - 3
working on 'origin/2014Q2' -  - 2
working on 'origin/2014Q1' -  - 1

That works. Interesting how we have both main and HEAD

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive