简体   繁体   中英

How can I get a list of git repositories, sorted by commit time?

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:

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}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM