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

git-force-clone #591

Merged
merged 6 commits into from
Oct 31, 2016
Merged

git-force-clone #591

merged 6 commits into from
Oct 31, 2016

Conversation

nottrobin
Copy link
Contributor

All files for git-force-clone, a command for overwriting local repos when closing repositories.

Provides the basic functionality of git clone, but if the destination
repository already exists it will force-reset it to resemble a clone of the
remote.

Because it doesn't actually delete the directory, it is usually significantly
faster than the alternative of deleting the directory and cloning the
repository from scratch.

I've only tested it on my laptop, running Ubuntu 16.04, in bash and zsh.

All files for git-force-clone, a command for overwriting local repos when closing repositories.
@hemanth
Copy link
Collaborator

hemanth commented Oct 29, 2016

LGTM

@hemanth hemanth closed this Oct 29, 2016
@hemanth hemanth reopened this Oct 29, 2016
while [[ -n "${1:-}" ]] && [[ "${1:0:1}" == "-" ]]; do
case $1 in
-b | --branch )
branch=${2:-}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a shift missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does shift at the end of the whole case block, which seems to work. Why do I need it in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I understand now - it needs to shift two values. I'll update.

_check "${remote_url}" "remote_url"
_check "${destination_path}" "destination_path"

if [ -d "${destination_path}/.git" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about existing directory which is not git repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This tool provides a solution just for existing git repos. If it's anything else, I figure it makes sense to pass it through to the standard git clone command and let it give the standard error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nottrobin
Or you need to clarity it in the docs: for target git repo instead of target directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spacewander Yep fair enough, I'll do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I've done that.


# Set default branch
if [ -z "${branch:-}" ]; then
branch=`git remote show origin | grep -oP '(?<=HEAD branch: )[^ ]+$'`
Copy link
Collaborator

Choose a reason for hiding this comment

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

A LC_ALL=C is required to bypass localization:

~/code/lua-resty-mooncake/test(master ✔) git remote show origin                                      
* 远程 origin
  获取地址:https://github.com/spacewander/lua-resty-mooncake
  推送地址:https://github.com/spacewander/lua-resty-mooncake
  HEAD 分支:master
  远程分支:
    master 已跟踪
  为 'git pull' 配置的本地分支:
    master 与远程 master 合并
  为 'git push' 配置的本地引用:
    master 推送至 master (最新)
~/code/lua-resty-mooncake/test(master ✔) LC_ALL=C git remote show origin              
* remote origin
  Fetch URL: https://github.com/spacewander/lua-resty-mooncake
  Push  URL: https://github.com/spacewander/lua-resty-mooncake
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool I'll add this.

exit 0
;;
* )
if [[ "${1:0:1}" == '-' ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this check duplicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I'll remove.

@nottrobin
Copy link
Contributor Author

@spacewander I've addressed 3 of your concerns. Let me know what you think about my response to the 4th - is it okay to simply let git clone handle the errors for when there's a non-git directory/file?

This expects a target git directory. If it's not a git directory,
(e.g. a simple directory) then it will pass through to
`git clone` which will raise an error.

Here I'm clarifying that this tool will reset local *git directories* specifically.
@nottrobin
Copy link
Contributor Author

@spacewander documentation updated. Let me know if you have any further issues.

@spacewander spacewander merged commit db62a6d into tj:master Oct 31, 2016
@spacewander
Copy link
Collaborator

Thanks!

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