-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: add ability to specify the git work directory #173
base: main
Are you sure you want to change the base?
Conversation
mcinj
commented
Aug 26, 2024
•
edited
Loading
edited
- can specify via cli or with the library, work-tree and git directory values allowing you to specify a repository outside of the current working directory
- created a repository object that stores work-tree and git directory values which are then used on any 'run' call to the git binary
- can specify via cli or with the library, work-tree and git directory values - created a repository object that stores work-tree and git directory values which are then used on any 'run' call to the git binary
tempDir := tempdir(t, true) | ||
localDir := dir(tempDir, "a-folder", t) | ||
defer func() { os.RemoveAll(localDir) }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using homemade tempdir instead of t.TempDir that comes with automatic cleanup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That function existed prior to this PR, but I believe the reason for it was that it also CDs into the temporary directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. It should be addressed outside the scope of this PR
cc @caarlos0
main.go
Outdated
@@ -53,6 +56,8 @@ func main() { | |||
Build: *build, | |||
Directory: *directory, | |||
TagMode: *tagMode, | |||
WorkTree: *workTree, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be better
WorkTree: *workTree, | |
GitWorkTree: *workTree, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to GitWorkTree
type Repository struct { | ||
GitWorkTree string | ||
GitDirectory string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but I didn't notice all this was in the git package
Maybe using git in git.Repository wasn't the best idea. Maybe @caarlos0 will provide some feedbacks here
func getAllTags(args ...string) ([]string, error) { | ||
tags, err := run(append([]string{"-c", "versionsort.suffix=-", "tag", "--sort=-version:refname"}, args...)...) | ||
// NewRepository creates a Repository. gitworktree and gitdirectory will default to 'pwd' and 'pwd/.git' | ||
func NewRepository(gitworktree, gitdirectory string) (*Repository, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be overkill when there is only two argument, but an Option pattern here may help a lot for readability.
func NewRepository(gitworktree, gitdirectory string) (*Repository, error) { | |
func NewRepository(opts...RepositoryOption) (*Repository, error) { |
So we can do
git.NewRepository(git.FromDirectory("whatever"))
git.NewRepository(git.FromWorkspace("whatever"))
I let @caarlos0 share his thoughts
tempDir := tempdir(t, true) | ||
localDir := dir(tempDir, "a-folder", t) | ||
defer func() { os.RemoveAll(localDir) }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. It should be addressed outside the scope of this PR
cc @caarlos0
@caarlos0, looking forward to any feedback you have. Although the PR is labeled as large due to the number of line changes, most of those are in unit tests. |