From b49f7844e09a29b6b2a5e6ef71c6c17b4c7ed9fc Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Jun 2019 04:56:49 +0200 Subject: git-changed-files: Get an absolute path to the files (WIP) A couple methods to get the absolute path to the changed files. This allows the output to be used to operate on changed files even if the current directory is not the repo root. Otherwise, all files are listed relative to the repository root. --- git-changed-files | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'git-changed-files') diff --git a/git-changed-files b/git-changed-files index 30a9c5c..615111f 100755 --- a/git-changed-files +++ b/git-changed-files @@ -1,3 +1,10 @@ #!/bin/sh git diff --name-only "$@" + +# Use absolute path in case the PWD is not the Git root +sed "s,/^,$(git rev-parse --show-toplevel)," +$(git rev-parse --show-toplevel) +awk '{ print "[CMD]" $0 }' + +git changed-files master.. | grep '_test\.go$' | awk -v git_root=$(git rev-parse --show-toplevel) '{ print git_root "/" $0 }' -- cgit v1.2.3