#444 [RFC] Fix clone --branches
Merged 4 years ago by onosek. Opened 4 years ago by tmz.

file modified
+5 -1
@@ -1546,7 +1546,8 @@ 

          conf_git = git.Git(os.path.join(path, git_dir))

          self._clone_config(conf_git, repo)

  

-         self._add_git_excludes(os.path.join(path, git_dir))

+         if not bare_dir:

+             self._add_git_excludes(os.path.join(path, git_dir))

  

          return

  
@@ -1625,6 +1626,9 @@ 

                  branch_git.config("--replace-all",

                                    "remote.%s.url" % self.default_branch_remote,

                                    giturl)

+ 

+                 # Add excludes

+                 self._add_git_excludes(branch_path)

              except (git.GitCommandError, OSError) as e:

                  raise rpkgError('Could not locally clone %s from %s: %s'

                                  % (branch, repo_path, e))

When cloning with the --branches option we first clone a bare repo
locally, then clone each branch from that bare repo.  Avoid adding an
excludes file to the temporary bare repo (which fails because we pass
the wrong path to the git dir).  Add an excludes file to each branch
dir.

Resolves: rhbz#1707223
Signed-off-by: Todd Zullinger <tmz@pobox.com>

I marked this RFC because it lacks tests. I don't have the time at the moment to create proper tests, so perhaps someone else can add those.

I don't think there are any tests for clone --branches or this would have been found when da320b4 ("Ignore files in a cloned repository", 2019-04-15) was added. So ideally there would be a basic test for the branches option and then potentially another test to ensure that the excludes file is added to each branch dir.

(Tangentially, I think the excludes patterns in fedpkg should be tightened up a bit, adding a leading / to anchor most of them at the root dir and a trailing / to results_* to make it clear it's a directory.)

Commit 0878a3a fixes this pull-request

Pull-Request has been merged by onosek

4 years ago

Thank you, I was previously working on my own fix, but your was better. I added the required tests for --branches argument to support this fix.

Excellent, thanks for adding those tests @onosek!

I don't use the --branches option myself, but seeing that it creates separate clones for each branch made me curious. I think git worktrees could solve this and might be easier to manage.

With worktrees, there would only be one .git dir and then a separate working directory for each branch. That should make it easier to share commits between branches (whether via git merge or git cherry-pick). It would also make it unnecessary to copy the excludes file to each branch dir.

I don't know if anyone who uses the --branches option would notice or not. I thought I would mention it in case anyone is looking to make further improvements in this area.

@tmz git worktre was already suggested before, but I think it ended with the finding, that git worktree is not supported on RHEL-6 and RHEL-7. In these distributions, git package is too old.

Ahh, that makes sense. I sometimes forget how ancient the git shipped with RHEL-6 and 7 are. :/

It might be possible on those releases to fudge it manually, with a .git file that points to the main repo, but I can't say I've tried that on the stock git in either RHEL 6/7. Maybe someone who uses the --branches option more will work on it down the road. (Whether it would be worth doing even if that works is another matter.)

Thanks.