bash read git log and print it to .xml format (RSS)

Well i`m trying to make a script that will read the output off git log and place this is a .xml file

here is a example of the script.

#!/bin/bash
repo=(/srv/git/repositories)
list1=($repo/test.git)
cd "$list1"

echo '<?xml version="1.0" ?><rss version="2.0"><channel>' >> /tmp/test.xml
for i in $(git log --pretty=format:"%h")
do
   for e in $(git log | grep "Author:" | awk '{print $2}')
   do
      #for f in $(git log --pretty=format:"%cn")
      #do
         #for g in $(git log --pretty=format:"%cD")
         #do
         cat << EOF >> /tmp/test.xml
         <item><title>$i</title><description></description><author>$e</author><pubDate></pubDate></item>
         EOF
         #done
      #done
     done
done
echo '</channel></rss>' >> /tmp/test.xml

When I do this this will result that each commit number and Author will be read and echoed multiple times. So I will get a .xml file like this:
Lots of same commit number!!

<rss version="2.0">
<channel>
   <item>
      <title>906feb6</title>
      <description/>
      <author>test</author>
      <pubDate/>
   </item>
   <item>
      <title>906feb6</title>
      <description/>
      <author>test</author>
      <pubDate/>
   </item>
   <item>
      <title>906feb6</title>
      <description/>
      <author>test</author>
      <pubDate/>
   </item>
   <item>
      <title>**906feb6**</title>
       <description/>
       <author>test1</author>
       <pubDate/>
    </item>
    <item>
       <title>**906feb6**</title>
       <description/>
       <author>test1</author>
       <pubDate/>
    <item>
    <title>**ffb521e**</title>
       <description/>
       <author>test1</author>
       <pubDate/>
    </item>
<channel></rss>

What I want is that each commit number has a author, description, and pubDate. But it has to get its information from those commands .

I want a output like this, could someone help?

<item>
   <title>906feb6</title>
   <description/>test commit 1</description>
   <author>test1</author>
   <pubDate>Mar, 18<pubDate/>
<item>
   <title>**ffb521e**</title>
   <description>test commit 2</description>
   <author>test2</author>
   <pubDate>Mar, 18<pubDate/>
</item>

  • Merging XML file changes in git
  • git log - how to get an xml output
  • Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException
  • Not showing branch name while fetching code using repo utility
  • Ignoring certain xml lines when merging
  • Can git be made to mostly auto-merge XML order-insensitive files?
  • What features make a file format friendly to VCS?
  • xslt cloning with partial data
  • One Solution collect form web for “bash read git log and print it to .xml format (RSS)”

    As @EtanReisner pointed out, you are looping over all commits in the inner loop, not just the one that the outer for loop is handling.

    Here’s how to avoid the for loops, and fix that problem.

    #!/bin/sh
    echo '<?xml version="1.0" ?><rss version="2.0"><channel>' > /tmp/test.xml  # Make sure we start with an empty file
    git log --pretty=format:"%h" |
    while read -r i; do
       # Presumably you want a single commit here
       # See also https://stackoverflow.com/a/4082178/874188
       # Also avoid Useless Use of grep
       e=$(git log "$i" -1 | awk '/^Author:/{print $2}')
       cat <<____EOF >> /tmp/test.xml
         <item><title>$i</title><description></description><author>$e</author><pubDate></pubDate></item>
    ____EOF
    done
    echo '</channel></rss>' >> /tmp/test.xml
    

    I see no reason to put the repo in two (sic!) arrays at the start. (If it’s just a single value, why use arrays at all?) Just run this in whichever repo you want to process.

    With that out of the way, there are no Bashisms in this script, so I changed the shebang to #!/bin/sh instead.

    To get the description etc into the snippet as well, maybe something like this instead (wrapped for legibility; should be just one line):

    git log "$i" -1 --format=format:"<item>%n <title>%h</title>
        %n <description>%s</description>%n <author>%an</author>
        %n <pubDate>%ad</pubDate>%n</item>"
    
    Git Baby is a git and github fan, let's start git clone.