GetFilesChanged returns a list of files which were changed, either between 2 commits, or at a single commit if you only supply one argument and a blank string for the other
(from, to string)
| 1564 | // commits, or at a single commit if you only supply one argument and a blank |
| 1565 | // string for the other |
| 1566 | func GetFilesChanged(from, to string) ([]string, error) { |
| 1567 | var files []string |
| 1568 | args := []string{ |
| 1569 | "-c", "core.quotepath=false", // handle special chars in filenames |
| 1570 | "diff-tree", |
| 1571 | "--no-commit-id", |
| 1572 | "--name-only", |
| 1573 | "-r", |
| 1574 | } |
| 1575 | |
| 1576 | if len(from) > 0 { |
| 1577 | args = append(args, from) |
| 1578 | } |
| 1579 | if len(to) > 0 { |
| 1580 | args = append(args, to) |
| 1581 | } |
| 1582 | args = append(args, "--") // no ambiguous patterns |
| 1583 | |
| 1584 | cmd, err := gitNoLFS(args...) |
| 1585 | if err != nil { |
| 1586 | return nil, errors.New(tr.Tr.Get("failed to find `git diff-tree`: %v", err)) |
| 1587 | } |
| 1588 | outp, err := cmd.StdoutPipe() |
| 1589 | if err != nil { |
| 1590 | return nil, errors.New(tr.Tr.Get("failed to call `git diff-tree`: %v", err)) |
| 1591 | } |
| 1592 | if err := cmd.Start(); err != nil { |
| 1593 | return nil, errors.New(tr.Tr.Get("failed to start `git diff-tree`: %v", err)) |
| 1594 | } |
| 1595 | scanner := bufio.NewScanner(outp) |
| 1596 | for scanner.Scan() { |
| 1597 | files = append(files, strings.TrimSpace(scanner.Text())) |
| 1598 | } |
| 1599 | if err := cmd.Wait(); err != nil { |
| 1600 | return nil, errors.New(tr.Tr.Get("`git diff-tree` failed: %v", err)) |
| 1601 | } |
| 1602 | |
| 1603 | return files, err |
| 1604 | } |
| 1605 | |
| 1606 | // IsFileModified returns whether the filepath specified is modified according |
| 1607 | // to `git status`. A file is modified if it has uncommitted changes in the |