Opened 13 years ago

Closed 11 years ago

Last modified 10 years ago

#27485 closed enhancement (fixed)

make "port sync" git - aware

Reported by: andy@… Owned by: ecronin (Eric Cronin)
Priority: Normal Milestone: MacPorts 2.3.0
Component: base Version: 2.2.99
Keywords: git, subversion, sync, haspatch Cc: ecronin (Eric Cronin), jeremyhu (Jeremy Huddleston Sequoia), nonstop.server@…, mklein-de (Michael Klein), cooljeanius (Eric Gallager)
Port:

Description

please let "port sync" detect a ".git"-macports repo instead of a subversion repository.

patch attached.

Attachments (4)

gitsync.patch (1.9 KB) - added by andy@… 13 years ago.
gitsync.2.patch (2.5 KB) - added by ecronin (Eric Cronin) 13 years ago.
updated patch to rebase git-svn repos
0001-Add-support-for-git-managed-portdirs.patch (3.1 KB) - added by ecronin (Eric Cronin) 12 years ago.
0001-Add-support-for-git-managed-portdirs2.patch (1.6 KB) - added by mklein-de (Michael Klein) 12 years ago.

Download all attachments as: .zip

Change History (20)

Changed 13 years ago by andy@…

Attachment: gitsync.patch added

comment:1 Changed 13 years ago by ecronin (Eric Cronin)

I just switched to a local git-svn repo and would like to see this too...

Attaching a new patch that adds a couple more features:

  • checking for $portdir/../.git is brittle, a better check is to run cd $portdir && git rev-parse --is-inside-work-tree 2>/dev/null >/dev/null which doesn't depend on a particular layout of the repository
  • the 'update' command is different for raw git versus git-svn so check which type the working-dir is and use the right one

comment:2 Changed 13 years ago by ecronin (Eric Cronin)

This needs some more work to match the behavior of svn. git pull and git svn fetch only bring the remote changes to the local repo, they don't apply them to the working copy for MacPorts to see... A git rebase or git svn rebase is also needed, likely surrounded by a git stash save/git stash pop combo and some error checking to clean up a failed merge...

Right now this patch is a slightly fancy NOOP from port sync's standpoint since the working tree doesn't change and no new updates get indexed.

Changed 13 years ago by ecronin (Eric Cronin)

Attachment: gitsync.2.patch added

updated patch to rebase git-svn repos

comment:3 Changed 12 years ago by ecronin (Eric Cronin)

Cc: ecronin@… added
Keywords: haspatch added

The change to .svn detection recently committed stopped my previous patch from applying cleanly, here's a new version which always includes the git stash save/pop step (I was incorrect in comment 3 I believe, a pull does a merge which should update the working directory)

I only test the git-svn half of the patch, but it has worked fine for 10 months now, blowing up a bit when manual intervention is needed because rebase or git stash pop has conflicts (I assume a failed svn update has the same issues on a dirty working directory), fixing the conflict and running selfupdate again is all that's needed

Changed 12 years ago by ecronin (Eric Cronin)

comment:4 Changed 12 years ago by ecronin (Eric Cronin)

Cc: jeremyhu@… added

r92410 does this for clean git repos, doesn't look like it handles git-svn or stashing any local modifications before trying to rebase

comment:5 Changed 12 years ago by nonstop.server@…

Cc: nonstop.server@… added

Cc Me!

comment:6 Changed 12 years ago by mklein-de (Michael Klein)

Cc: michael.klein@… added

Cc Me!

comment:7 Changed 12 years ago by mklein-de (Michael Klein)

I have two concerns regarding r92410:

  • it only works if $portdir is the repository root directory, so it doesn't even work for git://git.macports.org/macports/trunk.git, where $portdir is in dports
  • it does a git pull --rebase. See http://git-scm.com/book/ch3-6.html#The-Perils-of-Rebasing how this can cause trouble. If one really wants to rebase, one can use git config --local pull.rebase true instead

So, can we have 0001-Add-support-for-git-managed-portdirs.patch applied instead, but without git stash save/pop? If there are no local modifications, git stash save doesn't seem to save anything, and the following git stash pop fails. IMO is't perfectly ok to have the user commit any modifications before syncing.

Changed 12 years ago by mklein-de (Michael Klein)

comment:8 Changed 11 years ago by cooljeanius (Eric Gallager)

Cc: egall@… added

Cc Me!

comment:9 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Some (trivial) changes in base cause this to fail to merge now. I'm considering this version:

Index: macports.tcl
===================================================================
--- macports.tcl	(revision 109219)
+++ macports.tcl	(working copy)
@@ -2233,8 +2233,14 @@
                         incr numfailed
                         continue
                     }
-                } elseif {$git_cmd ne {} && [file exists ${portdir}/.git]} {
-                    set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
+                } elseif {$git_cmd ne {} && ![catch {exec sh -c "cd ${portdir} && $git_cmd rev-parse --is-inside-work-tree"} result]} {
+                    # determine what type of git repository this is
+                    if {![catch {exec sh -c "cd ${portdir} && $git_cmd config --local --get svn-remote.svn.url"} result]} {
+                        set git_action "svn rebase"
+                    } else {
+                        set git_action "pull --rebase"
+                    }
+                    set git_commandline "cd ${portdir} && $git_cmd $git_action"
                     ui_debug $git_commandline
                     if {
                         [catch {

comment:10 Changed 11 years ago by ecronin (Eric Cronin)

That's basically the same as my current local patch, except I switched to pushd/popd to match the changes made to svn, and fixed a message.

diff --git a/base/src/macports1.0/macports.tcl b/base/src/macports1.0/macports.tcl
index 3367705..646d337 100644
--- a/base/src/macports1.0/macports.tcl
+++ b/base/src/macports1.0/macports.tcl
@@ -2233,8 +2233,14 @@ proc mportsync {{optionslist {}}} {
                         incr numfailed
                         continue
                     }
-                } elseif {$git_cmd ne {} && [file exists ${portdir}/.git]} {
-                    set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
+                } elseif {$git_cmd ne {} && ![catch {exec sh -c "cd ${portdir} && $git_cmd rev-parse --is-inside-work-tree"} result]} {
+                    # determine what type of git repository this is
+                    if {![catch {exec sh -c "cd ${portdir} && $git_cmd config --local --get svn-remote.svn.url"} result]} {
+                        set git_action "svn rebase"
+                    } else {
+                        set git_action "pull --rebase"
+                    }
+                    set git_commandline "pushd $portdir ; $git_cmd $git_action ; popd || true"
                     ui_debug $git_commandline
                     if {
                         [catch {
@@ -2253,7 +2259,7 @@ proc mportsync {{optionslist {}}} {
                         }]
                     } {
                         ui_debug $::errorInfo
-                        ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
+                        ui_error "Synchronization of the local ports tree failed doing a git update"
                         incr numfailed
                         continue
                     }

comment:11 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Might want to just use --git-dir=${portdir}/.git --work-tree=${portdir} rather than the push/pop

comment:12 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Ok, would you mind giving this a sanity check for me? If it looks good to you, I'll push. Thanks.

~/src/macports/base/src/macports1.0 $ svn diff
Index: macports.tcl
===================================================================
--- macports.tcl	(revision 109219)
+++ macports.tcl	(working copy)
@@ -2234,7 +2234,13 @@
                         continue
                     }
                 } elseif {$git_cmd ne {} && [file exists ${portdir}/.git]} {
-                    set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
+                    # determine what type of git repository this is
+                    if {![catch {exec sh -c "$git_cmd --git-dir=${portdir}/.git config --local --get svn-remote.svn.url"} result]} {
+                        set git_action "svn rebase"
+                    } else {
+                        set git_action "pull --rebase"
+                    }
+                    set git_commandline "$git_cmd --git-dir=${portdir}/.git --work-tree=${portdir} $git_action"
                     ui_debug $git_commandline
                     if {
                         [catch {
@@ -2253,7 +2259,7 @@
                         }]
                     } {
                         ui_debug $::errorInfo
-                        ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
+                        ui_error "Synchronization of the local ports tree failed doing a git update"
                         incr numfailed
                         continue
                     }

comment:13 Changed 11 years ago by ecronin (Eric Cronin)

That forces $portdir to be the top level of the git checkout, while changing into $portdir and seeing if git can find .git in any parent subdir lets you check out the whole macports tree and point your sources.conf at the dports subdirectory under it...

Last edited 11 years ago by ecronin (Eric Cronin) (previous) (diff)

comment:14 Changed 11 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Owner: changed from macports-tickets@… to ecronin@…

I pushed my changes in r109747. Feel free to push your modifications.

comment:15 Changed 11 years ago by ecronin (Eric Cronin)

Milestone: MacPorts Future
Resolution: fixed
Status: newclosed
Version: 1.9.22.2.99

Added support for pointing to dports in a subdir of a full checkout of macports in r111086

I tried using $git_cmd rev-parse --git-dir to avoid the cd/pushd in later invocations, but --work-tree also looks like it needs to point to the top level not a subdirectory (could have used it for git config I suppose but this version I've been running for a couple years and trust).

comment:16 Changed 10 years ago by jmroot (Joshua Root)

Milestone: MacPorts FutureMacPorts 2.3.0
Note: See TracTickets for help on using tickets.