GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — clibrowser/cligit/src/commands/status.rs at main · allthingssecurity/clibrowser

Expand file tree

/

status.rs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
86 lines (78 loc) · 3.61 KB
/

status.rs

Copy path

File metadata and controls

86 lines (78 loc) · 3.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use anyhow::Result;
use git2::StatusOptions;
use crate::cli::StatusArgs;
use crate::git_ctx::GitContext;
use crate::models::*;
use crate::output::OutputConfig;
pub fn execute(_args: StatusArgs, ctx: &GitContext, out: &OutputConfig) -> Result<i32> {
let repo = &ctx.repo;
let mut opts = StatusOptions::new();
opts.include_untracked(true).renames_head_to_index(true);
let statuses = repo.statuses(Some(&mut opts))?;
let mut staged = Vec::new();
let mut modified = Vec::new();
let mut untracked = Vec::new();
let mut conflicts = Vec::new();
for entry in statuses.iter() {
let path = entry.path().unwrap_or("").to_string();
let s = entry.status();
if s.is_conflicted() {
conflicts.push(StatusEntry { path, status: "conflict".into() });
} else if s.is_index_new() || s.is_index_modified() || s.is_index_deleted() || s.is_index_renamed() || s.is_index_typechange() {
let st = if s.is_index_new() { "added" } else if s.is_index_deleted() { "deleted" } else if s.is_index_renamed() { "renamed" } else { "modified" };
staged.push(StatusEntry { path: path.clone(), status: st.into() });
// File can be both staged and have unstaged changes
if s.is_wt_modified() || s.is_wt_deleted() {
let wt = if s.is_wt_deleted() { "deleted" } else { "modified" };
modified.push(StatusEntry { path, status: wt.into() });
}
} else if s.is_wt_new() {
untracked.push(StatusEntry { path, status: "untracked".into() });
} else if s.is_wt_modified() || s.is_wt_deleted() {
let st = if s.is_wt_deleted() { "deleted" } else { "modified" };
modified.push(StatusEntry { path, status: st.into() });
}
}
let branch = repo.head().ok().and_then(|h| h.shorthand().map(String::from));
let head_sha = repo.head().ok().and_then(|h| h.target()).map(|o| o.to_string());
let (upstream, ahead, behind) = match repo.head().ok().and_then(|h| {
let name = h.shorthand()?.to_string();
let local = repo.find_branch(&name, git2::BranchType::Local).ok()?;
let up = local.upstream().ok()?;
let up_name = up.name().ok()??.to_string();
let local_oid = h.target()?;
let up_oid = up.get().target()?;
let (a, b) = repo.graph_ahead_behind(local_oid, up_oid).ok()?;
Some((Some(up_name), a, b))
}) {
Some((u, a, b)) => (u, a, b),
None => (None, 0, 0),
};
let counts = StatusCounts {
staged: staged.len(),
modified: modified.len(),
untracked: untracked.len(),
conflicts: conflicts.len(),
};
let clean = staged.is_empty() && modified.is_empty() && untracked.is_empty() && conflicts.is_empty();
let result = StatusResult {
branch, head_sha, upstream, ahead, behind,
staged, modified, untracked, conflicts, clean, counts,
};
if out.json {
out.print_json(&result);
} else {
if let Some(ref b) = result.branch {
out.print_human(&format!("On branch {}", b));
}
if result.clean {
out.print_human("nothing to commit, working tree clean");
} else {
for e in &result.staged { out.print_human(&format!(" staged: {} ({})", e.path, e.status)); }
for e in &result.modified { out.print_human(&format!(" modified: {} ({})", e.path, e.status)); }
for e in &result.untracked { out.print_human(&format!(" untracked: {}", e.path)); }
for e in &result.conflicts { out.print_human(&format!(" conflict: {}", e.path)); }
}
}
Ok(0)
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.