1

I set up my own server to host some private git repositories.

I am working on a visual representation (using a php backend) of my private 'repo base'.
It all works fine and I may open-source it at some point.


My current issue: Creating a list of all repositories (I did that already), which is sorted by the last commit times (to the master-branches).

I currently use this function to get a list of my (bare) git repositories:

function listRepositories() {
  global $SYSTEM_PATH;

  exec("ls $SYSTEM_PATH/repos/ -t", $repoDirectories);

  $repos = array_map(function($repo) {
    return str_replace("$SYSTEM_PATH/repos/", "", $repo);
  }, $repoDirectories);

  return $repos;
}

However, the ls $SYSTEM_PATH/repos/ -t command I currently use to get a list of repos does not sort them the way I want.
If I copy older repos into the repository directory ($SYSTEM_PATH/repos/), they appear on top of the list.

This command returns the last commit time (unix timestamp):

git log -1 --format=%ct

However, I did not yet manage to combine all that to achieve what I want in a efficient way.


Thank you for helping me achieve it, I am grateful for everything this community taught me!


Related Questions:

finnmglas
  • 1,626
  • 4
  • 22
  • 37

1 Answers1

1

You need to go into every repository in a loop, output the last commit timestamp in a sortable format (let's use unix time), sort and output sorted repo names:

find $SYSTEM_PATH/repos/ -maxdepth 1 -type d |
while read repo; do
    git -C "$repo" --no-pager log -1 --format="%ct $repo" 2>/dev/null
done | sort -nr | awk '{print $2}'
phd
  • 82,685
  • 13
  • 120
  • 165