See list of modified files in repo folder

Absolutely! Let's break down this full command character by character and explain each flag, each component, and what it does:


πŸ”§ FULL COMMAND:

repo forall -c 'git status --short | while read status file; do echo "$(pwd)/$file"; done'

βœ… High-Level Goal:

This command prints the absolute paths of all modified or untracked files in your current AOSP repo working tree.


πŸ“Œ PART 1: repo forall -c '...'

1️⃣ repo

  • A command-line tool provided by AOSP (Android Open Source Project) to manage multiple Git repositories under one parent tree.

2️⃣ forall

  • Tells repo to run a command for each project (each Git repo) in your workspace.

3️⃣ -c

  • Short for command.

  • Tells repo to run the command you provide in single quotes '...' inside each project directory.

  • That command will execute in the context of each project directory, i.e., the shell will cd into that project folder first.


πŸ“Œ PART 2: 'git status --short | while read status file; do echo "$(pwd)/$file"; done'

This is the actual shell command run inside each Git project.

πŸ”Ή git status --short

πŸ”Έ git

  • Invokes Git, the version control system.

πŸ”Έ status

  • Shows the current status of the working directory and staging area (like changes to tracked and untracked files).

πŸ”Έ --short

  • Provides output in a compact format. Each line shows:

    • 2-character status (staged/unstaged/untracked etc.)

    • Followed by the relative path of the file.

🧠 Example output of git status --short:

πŸ”Ή |

  • This pipe symbol takes the output of the left command (git status --short) and feeds it as input to the command on the right (while read ...).


πŸ”Ή while read status file; do ...; done

πŸ”Έ while read status file; do ...; done

  • A shell while-loop that reads each line from the input (here from git status --short).

  • Each line is split into:

    • status – the first column (like M, ??, etc.)

    • file – the file path (like Android.bp)

πŸ’‘ read will break a line into variables separated by whitespace. So in each loop iteration:

  • status holds the two-character Git status

  • file holds the relative file path


πŸ”Ή echo "$(pwd)/$file"

πŸ”Έ echo

  • Prints a string to stdout (terminal).

πŸ”Έ "$(pwd)/$file"

  • "$(pwd)":

    • Executes the pwd command (print working directory).

    • This gives the absolute path of the current project folder being processed by repo forall.

  • "$file":

    • Appends the relative file path from git status output.

πŸ”„ The combined string is:

For example, if:

  • Current directory = /media/shreyas/AOSP/OperatorPreferenceMenu

  • File = Android.bp

Then:


πŸ”„ FLOW DIAGRAM SUMMARY:

  1. repo forall -c '...' ➜ Loop through all Git projects in AOSP workspace.

  2. Inside each project: ➜ Run git status --short ➜ Output like: M Android.bp

  3. Pipe it into while read status file; do ... done ➜ For each line, extract status and file name

  4. For each file: ➜ Run echo "$(pwd)/$file" ➜ Prints absolute path of the modified or untracked file.


πŸ§ͺ Example:

Let's say your repo workspace is in:

And inside OperatorPreferenceMenu, you modified Android.bp.

Then this command would output:


πŸ“Œ Notes:

  • This command doesn't list unchanged files.

  • It only shows files that are modified (M), added (A), deleted (D), or untracked (??) in each Git repo.

  • You can use this to script or locate modified files across a huge AOSP tree.


Would you like a version of this command that includes the Git status symbol along with the absolute path too?

Last updated