| 471 | 471 | | return next(1).map(str::to_owned); |
| 472 | 472 | | } |
| 473 | 473 | | "push" if at > 0 && words[at - 1] == "git" || at > 1 && words[at - 2] == "git" => { |
| 474 | | − | let rest: Vec<&str> = words[at + 1..].iter().copied().filter(|w| !w.starts_with('-')).collect(); |
| 474 | + | // Its own words only: a pipe, a redirect or the next command is not a branch. |
| 475 | + | let rest: Vec<&str> = words[at + 1..] |
| 476 | + | .iter() |
| 477 | + | .copied() |
| 478 | + | .take_while(|w| !w.contains(['|', '>', '<']) && !matches!(*w, "&&" | ";" | "&")) |
| 479 | + | .filter(|w| !w.starts_with('-')) |
| 480 | + | .collect(); |
| 475 | 481 | | if let Some(branch) = rest.get(1) { |
| 476 | 482 | | let branch = branch.trim_matches(|c| c == ';' || c == '&'); |
| 477 | 483 | | let branch = branch.rsplit(':').next().unwrap_or(branch).trim_start_matches("refs/heads/"); |
| ⋯ |
| 1745 | 1751 | | assert_eq!(branch_in("git checkout -b 4-greet"), Some("4-greet".into())); |
| 1746 | 1752 | | assert_eq!(branch_in("cd web && git push origin HEAD:4-greet"), Some("4-greet".into())); |
| 1747 | 1753 | | assert_eq!(branch_in("git status"), None); |
| 1754 | + | // A pipe or a redirect is not a branch. |
| 1755 | + | assert_eq!(branch_in("git push -u origin 2-age 2>&1 | tail -3"), Some("2-age".into())); |
| 1756 | + | assert_eq!(branch_in("git push origin | tail -1"), None); |
| 1757 | + | assert_eq!(branch_in("git push origin && g1t pr checks"), None); |
| 1748 | 1758 | | assert_eq!(summarize("bash", &json!({ "command": "curl -H x token=abc" })), "bash: curl -H x …"); |
| 1749 | 1759 | | } |
| 1750 | 1760 | | |