Skip to content

FIX: Unset GIT_DIR environment variable while retrieving version information from git#280

Merged
effigies merged 4 commits intopython-versioneer:masterfrom
effigies:fix/override_GIT_DIR
Mar 7, 2022
Merged

FIX: Unset GIT_DIR environment variable while retrieving version information from git#280
effigies merged 4 commits intopython-versioneer:masterfrom
effigies:fix/override_GIT_DIR

Conversation

@effigies
Copy link
Copy Markdown
Contributor

@effigies effigies commented Jan 11, 2022

Closes #279.

Unclear whether there should be a config variable to allow for different .git locations. May not be worth the complexity to cover if the edge case is never actually hit.

@effigies effigies force-pushed the fix/override_GIT_DIR branch 4 times, most recently from e13f169 to 16540cd Compare February 19, 2022 04:01
@effigies effigies marked this pull request as ready for review February 19, 2022 04:03
@effigies effigies added this to the 0.22 milestone Feb 19, 2022
@effigies effigies force-pushed the fix/override_GIT_DIR branch from a7c822b to 875fa45 Compare February 20, 2022 02:06
@effigies effigies changed the title ENH: Set --git-dir=.git to prevent GIT_DIR overrides ENH: Prevent GIT_DIR overrides by setting --git-dir and --work-tree in git commands Feb 20, 2022
@effigies effigies force-pushed the fix/override_GIT_DIR branch 3 times, most recently from 3a176bd to faf3122 Compare February 20, 2022 15:24
@effigies effigies force-pushed the fix/override_GIT_DIR branch from faf3122 to 725ea8d Compare February 20, 2022 15:28
@effigies effigies changed the title ENH: Prevent GIT_DIR overrides by setting --git-dir and --work-tree in git commands FIX: Unset GIT_DIR environment variable while retrieving version information from git Feb 20, 2022
Copy link
Copy Markdown
Contributor

@mathijsvdv mathijsvdv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed your code and added the pull request effigies#1 with my suggested changes. Have a look!

@mih
Copy link
Copy Markdown

mih commented Feb 24, 2022

I tried this PR in the context of the functionality were you identified the previous fix for the interference of GIT_DIR with versioneer (context mih/datalad-mihextras#9). With this change, it leads to an unconditional fatal: KeyError('GIT_DIR') in that implementation, because it must obtain the GIT_DIR setting provided by Git to the remote helper process via this environment variable.

It seems with this PR the GIT_DIR is removed from the process environment -- and not only for versioneer, but entirely. This breaks the environment that Git remote helpers must operate in.

The relevant change seems to be this one:

-    out, rc = run_command(GITS, ["--git-dir=.git", "rev-parse", "--git-dir"], cwd=root,
-                          hide_stderr=True)
+    # GIT_DIR can interfere with correct operation of Versioneer.
+    # It may be intended to be passed to the Versioneer-versioned project,
+    # but that should not change where we get our version from.
+    os.environ.pop("GIT_DIR", None)
+
+    _, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root,
+                   hide_stderr=True)

(from diff'ing the effective change to that DataLad extension package's code after updating versioneer in it).

It would be great if the environment modification could be constraint to versioneer itself, rather than effecting the entire process.

Thx!

@effigies
Copy link
Copy Markdown
Contributor Author

Did you apply the mock as well? That is intended to protect the environment from being changed downstream.

@mih
Copy link
Copy Markdown

mih commented Feb 24, 2022

I did not do any custom editing. I only reinstalled versioneer in the project, assuming that would be enough.

@effigies
Copy link
Copy Markdown
Contributor Author

Hmm. Okay. Let me try again...

@effigies effigies force-pushed the fix/override_GIT_DIR branch from bfdf761 to 156afd1 Compare February 24, 2022 13:33
@effigies
Copy link
Copy Markdown
Contributor Author

Missed @mathijsvdv's PR. Seems like a better approach.

@effigies
Copy link
Copy Markdown
Contributor Author

Okay, Windows tests are passing, which was the big hold up before.

@mih Can you try again with these updates?

@effigies
Copy link
Copy Markdown
Contributor Author

effigies commented Mar 3, 2022

Hey @mih, have you had a chance to check this? If we fail again, could you share a reproduction?

@mih
Copy link
Copy Markdown

mih commented Mar 7, 2022

Sorry for the delay. I was now able to verify that things are splendid now! Thx much for taking the time to wait for the feedback! Looking forward to the coming release.

@effigies effigies merged commit de0c35d into python-versioneer:master Mar 7, 2022
@effigies
Copy link
Copy Markdown
Contributor Author

effigies commented Mar 7, 2022

Thanks for testing! Will plan to release today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle GIT_DIR overrides

3 participants