Skip to content

Argument for git repo directory#2

Closed
Oakchris1955 wants to merge 4 commits intoHigangssh:mainfrom
Oakchris1955:main
Closed

Argument for git repo directory#2
Oakchris1955 wants to merge 4 commits intoHigangssh:mainfrom
Oakchris1955:main

Conversation

@Oakchris1955
Copy link
Copy Markdown

Before I begin, this is the first time I write Go code, so I don't know whether it's good or not.

So, I saw this and thought "no way this don't have an argument for setting the git repo target directory without having to navigate to it". Turns out, there isn't such a thing, so I wrote it in like 30 mins.

@Oakchris1955 Oakchris1955 marked this pull request as draft March 28, 2026 18:48
@Oakchris1955
Copy link
Copy Markdown
Author

There seem to be some issues with my argument parsing, so I will fix that and remark as ready for review

@Oakchris1955 Oakchris1955 marked this pull request as ready for review March 29, 2026 12:50
@Oakchris1955 Oakchris1955 deleted the branch Higangssh:main April 4, 2026 12:24
@Oakchris1955 Oakchris1955 deleted the main branch April 4, 2026 12:24
@Oakchris1955 Oakchris1955 restored the main branch April 4, 2026 12:24
@Oakchris1955 Oakchris1955 reopened this Apr 4, 2026
@Higangssh
Copy link
Copy Markdown
Owner

@Oakchris1955 Thanks for the contribution — supporting a target repository directory is a useful improvement for the CLI.

Before I can merge this, I’d like to request a few changes:

  1. Please avoid using os.Chdir() inside getRepoInfo()
  • Changing the process working directory introduces global side effects
  • Please keep the current working directory unchanged and access the target repository explicitly instead
  • For example, use filepath.Join(dir, ...) for files and git -C <dir> ... for git commands
  1. Please make the directory a properly parsed positional argument
  • The current parsing logic is fragile because it depends on argument order
  • Please parse flags first, then read at most one positional directory argument explicitly
  1. Please return errors instead of calling os.Exit(1) inside helper functions
  • getRepoInfo() should return (repoInfo, error)
  • Then main() can decide how to print the error and exit
  • This will make the code easier to test and maintain
  1. Please add tests for the new behavior
  • current directory
  • another repository path
  • invalid directory
  • GIF generation for a target repository

I like the feature itself, so if you update the PR in that direction, I’d be happy to take another look.

@Oakchris1955
Copy link
Copy Markdown
Author

The current parsing logic is fragile because it depends on argument order

That is your own parsing logic. If anything, you should fix it.

Please return errors instead of calling os.Exit(1) inside helper functions

That's something I saw in your code, that's why I copied you behaviour

@Higangssh
Copy link
Copy Markdown
Owner

@Oakchris1955 Fair point — this started as a small utility project, and I did not pay enough attention to code quality early on, so some of these patterns do exist in the current codebase.

The project has gotten more attention than I expected, though, and I want to raise the bar going forward rather than add more of the same patterns.

For this PR, the changes I still need before merging are:

  1. avoid changing the process working directory with os.Chdir()

    • please access the target repository explicitly instead, for example with filepath.Join(...) or git -C <dir>
  2. parse the directory as a proper positional argument

    • the current logic is too dependent on argument order
  3. return errors from helper functions instead of calling os.Exit(1)

    • main() should handle printing and exiting
  4. add tests for the new behavior

    • current directory
    • another repository path
    • invalid directory
    • GIF generation with a target repository

If updating every part of this is too much for one PR, I am also fine splitting some cleanup into a follow-up change on my side. But I still want to avoid adding more of these patterns in new code.

If you want to update the PR in that direction, I am happy to review it again.

@Higangssh Higangssh self-requested a review April 7, 2026 13:57
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.

2 participants