Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins.fetchGit improvement with unclean repo's #1933

Closed
cleverca22 opened this issue Mar 1, 2018 · 5 comments
Closed

builtins.fetchGit improvement with unclean repo's #1933

cleverca22 opened this issue Mar 1, 2018 · 5 comments
Assignees
Labels
feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI.

Comments

@cleverca22
Copy link
Contributor

try {
runProgram("git", true, { "-C", uri, "diff-index", "--quiet", "HEAD", "--" });
} catch (ExecError e) {
if (!WIFEXITED(e.status) || WEXITSTATUS(e.status) != 1) throw;
clean = false;
}
if (!clean) {

currently, if a repo is not clean, fetchGit returns all 0's for the revision

my proposal, is that it return the current revision, and boolean flag to indicate that it has been modified, so you at least know what the starting point is, rather then having no clue what the version is

for example:

nix-repl> builtins.fetchGit ./.
{ outPath = "/nix/store/311jjk1bcwqzb0fi7xial2lrz6wr14s3-source"; rev = "72cab907664d22b4dea0d1590f881d6cd0bbf36f"; revCount = 16; shortRev = "72cab90"; modified = true; }
@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@grahamc
Copy link
Member

grahamc commented Jul 4, 2018

or perhaps using <commit>-dirty, like how git describe --dirty will

@kaii-zen
Copy link
Contributor

In one of the projects I work on I actually id the "dirt" as it helps when I want to deploy things for testing before actually committing. The easiest way I found for doing that is to just use GIT_INDEX_FILE to create an index in a temp file and then hashing the output of git diff:

export GIT_INDEX_FILE=$(mktemp -d)/idx
git add --all
git --no-pager diff --no-color HEAD | git hash-object --stdin
rm $GIT_INDEX_FILE

Here's a fairly more robust (albeit still contrived) version https://gist.github.com/kreisys/2fd049bd8c6f40a412067bead6184923
if you save it to /usr/local/bin/git-dirt then you can run git dirt to get the dirt hash or git dirt -s for the short version.

@stale
Copy link

stale bot commented Feb 14, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 14, 2021
@fricklerhandwerk fricklerhandwerk added feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI. and removed improvement labels Oct 6, 2022
@stale stale bot removed stale labels Oct 6, 2022
@mkohler
Copy link

mkohler commented Aug 26, 2023

It looks to me like a feature very similar to this was implemented in #5385 and merged to master on June 24, 2023.

@roberth
Copy link
Member

roberth commented Oct 7, 2023

This has been implemented in #5385. Thanks @mkohler.

nix-repl> builtins.fetchGit ./.
warning: Git tree '/home/user/src/nix' is dirty
{
  dirtyRev = "644ebaab5f96089bc3a8fd3873e8e7f2131a9074-dirty"; 
  dirtyShortRev = "644ebaab5-dirty"; 
  lastModified = 1696604297; 
  lastModifiedDate = "20231006145817"; 
  narHash = "sha256-xxDbF1XGBSxgFekFjYVVwhwFe2bMaKyoeHgaj2btYH8="; 
  outPath = "/nix/store/1r3n5s4pv4jcpxiw6akjqwc0yz8ki3ah-source"; 
  rev = "0000000000000000000000000000000000000000"; 
  revCount = 0; 
  shortRev = "0000000"; 
  submodules = false;
}

@roberth roberth closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI.
Projects
None yet
Development

No branches or pull requests

9 participants