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

disambiguate git command #193

Merged
merged 4 commits into from
Oct 14, 2021
Merged

disambiguate git command #193

merged 4 commits into from
Oct 14, 2021

Conversation

thumbnail
Copy link
Member

@thumbnail thumbnail commented Oct 12, 2021

Brief

Previously local files could collide with the passed target-branch. This would yield an error like 'fatal: ambiguous argument 'main': both revision and filename'.

QA plan

also executed in test as of 6d5e122

  1. change files
  2. stage files
  3. run (strategies/git-diff-against-default-branch :target-branch "main"), assert seq of filenames
  4. run $ touch master
  5. run (strategies/git-diff-against-default-branch :target-branch "main") again, assert seq of filenames

Step 5 will fail on current main by returning nil.

Author checklist

  • I have QAed the functionality
  • The PR has a reasonably reviewable size and a meaningful commit history
  • I have run the branch formatter and observed no new/significative warnings
  • The build passes
  • I have self-reviewed the PR prior to assignment
  • Additionally, I have code-reviewed iteratively the PR considering the following aspects in isolation:
    • Correctness
    • Robustness (red paths, failure handling etc)
    • Test coverage
    • Spec coverage
    • Documentation
    • Security
    • Performance
    • Breaking API changes
    • Cross-compatibility (Clojure/ClojureScript)

Reviewer checklist

  • I have checked out this branch and reviewed it locally, running it
  • I have QAed the functionality
  • I have reviewed the PR
  • Additionally, I have code-reviewed iteratively the PR considering the following aspects in isolation:
    • Correctness
    • Robustness (red paths, failure handling etc)
    • Test coverage
    • Spec coverage
    • Documentation
    • Security
    • Performance
    • Breaking API changes
    • Cross-compatibility (Clojure/ClojureScript)

Previously local files could collide with the passed target-branch. This would yield an error like 'fatal: ambiguous argument 'main': both revision and filename'.
@thumbnail thumbnail requested review from a team, josefigueroa-nedap and lennartbuit and removed request for a team October 12, 2021 09:56
Copy link
Contributor

@vemv vemv left a comment

Choose a reason for hiding this comment

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

Would it make sense to craft a test explicitly for this corner case?

@thumbnail thumbnail force-pushed the disambiguate-git-diff branch from e99759c to 17f1aac Compare October 12, 2021 10:06
(let [file (io/as-file "main")]
(try
(spit file "test file")
(is (sut/git-ref-exists? "main"))
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

If it's not an excessive burden I'd test git-diff-against-default-branch itself

Copy link
Member Author

Choose a reason for hiding this comment

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

This test wouldn't fail on main, so i removed it.

I added a test for git-diff-against-default-branch, which was a pretty rough test to write, but it should be fine now :)

@thumbnail thumbnail force-pushed the disambiguate-git-diff branch from 24bc89a to 6d5e122 Compare October 12, 2021 14:01
(try
;; creating a file with a filename which collides with a sha.
(spit ambiguous-file creatable-contents)
(expect-sane-output! (sut/git-diff-against-default-branch :target-branch @root-commit))
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this assertion is programmatic/dynamic we can't be exactly sure of what is being asserted here? As the name hints, it only asserts some basic 'sanity' not correctness/completeness.

I wouldn't remove it, but additionally I would assert something related to the filename named after root-commit

Copy link
Member Author

Choose a reason for hiding this comment

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

The expect-sane-output! asserts that sut/git-diff-against-default-branch returns at least 1 file. Without the patch the function will return nil. In this specific case the filename shouldn't be part of the diff but imo it doesn't matter (like the other cases in this test).

What would you suggest be asserted besides the existing assertions?

Copy link
Contributor

Choose a reason for hiding this comment

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

In this specific case the filename shouldn't be part of the diff

When I see (spit ambiguous-file creatable-contents) I'd expect that file to be part of the diff

Maybe if we temporarily git add -A it should? (don't quote me on that, just quickly eyeing things on github)

In which case it would be good to exercise both cases (added , not added)

Copy link
Member Author

Choose a reason for hiding this comment

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

The test exists to assert it runs without errors, exercising its specs. Testing the actual functionality of sut/git-diff-against-default-branch is out of scope for this test.

However, such a test is missing, so I added this issue to keep track: #194

Comment on lines 166 to 169
(let [ambiguous-file (io/file git-integration-dir @root-commit)]
(try
;; creating a file with a filename which collides with a sha.
(spit ambiguous-file creatable-contents)

Choose a reason for hiding this comment

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

git-sha-named-file, maybe? I'm having trouble following this test

@thumbnail thumbnail merged commit 80a5d98 into main Oct 14, 2021
@thumbnail thumbnail deleted the disambiguate-git-diff branch October 14, 2021 09:57
@thumbnail thumbnail mentioned this pull request Oct 14, 2021
7 tasks
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.

3 participants