|
| 1 | +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use std::path::Path; |
| 12 | + |
| 13 | +const CARGO_LOCK: &'static str = "Cargo.lock"; |
| 14 | + |
| 15 | +pub fn check(path: &Path, bad: &mut bool) { |
| 16 | + use std::process::Command; |
| 17 | + |
| 18 | + super::walk(path, |
| 19 | + &mut |path| super::filter_dirs(path) || path.ends_with("src/test"), |
| 20 | + &mut |file| { |
| 21 | + let name = file.file_name().unwrap().to_string_lossy(); |
| 22 | + if name == CARGO_LOCK { |
| 23 | + let rel_path = file.strip_prefix(path).unwrap(); |
| 24 | + let ret_code = Command::new("git") |
| 25 | + .arg("diff-index") |
| 26 | + .arg("--quiet") |
| 27 | + .arg("HEAD") |
| 28 | + .arg(rel_path) |
| 29 | + .current_dir(path) |
| 30 | + .status() |
| 31 | + .unwrap_or_else(|e| { |
| 32 | + panic!("could not run git diff-index: {}", e); |
| 33 | + }); |
| 34 | + if !ret_code.success() { |
| 35 | + let parent_path = file.parent().unwrap().join("Cargo.toml"); |
| 36 | + print!("dirty lock file found at {} ", rel_path.display()); |
| 37 | + println!("please commit your changes or update the lock file by running:"); |
| 38 | + println!("\n\tcargo update --manifest-path {}", parent_path.display()); |
| 39 | + *bad = true; |
| 40 | + } |
| 41 | + } |
| 42 | + }); |
| 43 | +} |
0 commit comments