@@ -65,10 +65,15 @@ func DiffCommit(dir string, ref string, compareRef string, options *DiffCommitOp
6565 var collectUntrackedFilesCmd string
6666
6767 var withTreeRef string
68+ var workingFlags string
6869 if ref != COMMIT_WORKING {
6970 defRef = fmt .Sprintf ("ref=$(git rev-parse --verify --quiet %s || true)" , sh .Quote (ref ))
7071 withTreeRef = "--with-tree $ref"
7172 } else {
73+ // -c cached (default)
74+ // -o others,including untracked
75+ workingFlags = "--exclude-standard -co"
76+
7277 collectUntrackedFilesCmd = "git ls-files --no-empty-directory --exclude-standard --others --full-name" + patternArg
7378 }
7479 res , err := RunCommand (dir , func (commands []string ) []string {
@@ -77,7 +82,7 @@ func DiffCommit(dir string, ref string, compareRef string, options *DiffCommitOp
7782 fmt .Sprintf ("compareRef=$(git rev-parse --verify --quiet %s || true)" , sh .Quote (compareRef )),
7883 // all new files
7984 "echo 'all-new-files:'" ,
80- fmt .Sprintf (`git ls-files %s %s` , withTreeRef , patternArg ),
85+ fmt .Sprintf (`git ls-files %s %s %s ` , withTreeRef , workingFlags , patternArg ),
8186 "echo -ne '\r \r \r \r \r \r '" ,
8287
8388 // all old files
@@ -88,17 +93,17 @@ func DiffCommit(dir string, ref string, compareRef string, options *DiffCommitOp
8893 // added files
8994 "echo 'added-files:'" ,
9095 fmt .Sprintf (`git diff --diff-filter=A --name-only --ignore-submodules "$compareRef" $ref -- %s|| true` , patternArg ),
91- // untracked files if
9296 "echo -ne '\r \r \r \r \r \r '" ,
9397
94- // added files
98+ // untracked files
9599 "echo 'untracked-files:'" ,
96100 collectUntrackedFilesCmd ,
97101 "echo -ne '\r \r \r \r \r \r '" ,
98102
99103 // modified files
104+ // add -c core.fileMode=false to ignore mode change
100105 "echo 'modified-files:'" ,
101- fmt .Sprintf (`git diff --diff-filter=M --name-only --ignore-submodules "$compareRef" $ref -- %s|| true` , patternArg ),
106+ fmt .Sprintf (`git -c core.fileMode=false diff --diff-filter=M --name-only --ignore-submodules "$compareRef" $ref -- %s|| true` , patternArg ),
102107 "echo -ne '\r \r \r \r \r \r '" ,
103108
104109 // // renamed files
@@ -170,6 +175,12 @@ func DiffCommit(dir string, ref string, compareRef string, options *DiffCommitOp
170175 // deleted files has two type of changes:
171176 // 1.deleted
172177 // 2.renamed to another file
178+ // an example:
179+ // HEAD: ab.txt
180+ // HEAD~1: a.txt b.txt
181+ // results: ab.txt: renamedFrom=a.txt,contentChanged=true
182+ // a.txt: deleted = true
183+ // b.txt: deleted = true
173184 fileDetailsMap [file ] = & FileDetail {
174185 Deleted : true , // it may be renmaed also
175186 }
0 commit comments