summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py81
-rw-r--r--tests.branching/branch-creates-new-system-branch-not-from-master.stdout1
-rw-r--r--tests.branching/branch-creates-new-system-branch.stdout1
-rw-r--r--tests.branching/checkout-existing-branch.stdout1
-rw-r--r--tests.branching/checkout-non-aliased-repos.stdout2
-rwxr-xr-xtests.branching/edit-checkouts-existing-chunk.script4
-rwxr-xr-xtests.branching/edit-clones-chunk.script5
-rwxr-xr-xtests.branching/edit-uses-ref-from-stratum.script2
-rwxr-xr-xtests.branching/merge-explicitly-named-repos.script4
-rwxr-xr-xtests.branching/workflow.script4
10 files changed, 69 insertions, 36 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 098546cf..74069200 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -98,6 +98,20 @@ class BranchAndMergePlugin(cliapp.Plugin):
raise cliapp.AppException("Can't find the system branch directory")
@staticmethod
+ def write_branch_root(branch_dir, repo):
+ filename = os.path.join(branch_dir, '.morph-system-branch',
+ 'branch-root')
+ with open(filename, 'w') as f:
+ f.write('%s\n' % repo)
+
+ @staticmethod
+ def read_branch_root(branch_dir):
+ filename = os.path.join(branch_dir, '.morph-system-branch',
+ 'branch-root')
+ with open(filename, 'r') as f:
+ return f.read().strip()
+
+ @staticmethod
def clone_to_directory(app, dirname, reponame, ref):
'''Clone a repository below a directory.
@@ -259,6 +273,9 @@ class BranchAndMergePlugin(cliapp.Plugin):
# this directory as a morph system branch.
os.mkdir(os.path.join(new_branch, '.morph-system-branch'))
+ # Remember the repository we branched off from.
+ self.write_branch_root(new_branch, self.system_repo_base)
+
# Clone into system branch directory.
new_repo = os.path.join(new_branch, self.system_repo_base)
self.clone_to_directory(self.app, new_repo, self.system_repo_name,
@@ -301,6 +318,9 @@ class BranchAndMergePlugin(cliapp.Plugin):
# this directory as a morph system branch.
os.mkdir(os.path.join(system_branch, '.morph-system-branch'))
+ # Remember the repository we branched off from.
+ self.write_branch_root(system_branch, repo)
+
# Clone into system branch directory.
repo_dir = os.path.join(system_branch, self._convert_uri_to_path(repo))
self.clone_to_directory(self.app, repo_dir, repo, system_branch)
@@ -313,21 +333,22 @@ class BranchAndMergePlugin(cliapp.Plugin):
def merge(self, args):
'''Merge specified repositories from another system branch.'''
- if len(args) == 0:
+ if len(args) < 2:
raise cliapp.AppException('morph merge must get a branch name '
'and some repo names as arguments')
- app = self.app
other_branch = args[0]
workspace = self.deduce_workspace()
this_branch = self.deduce_system_branch()
for repo in args[1:]:
- repo = self.resolve_reponame(app, repo)
- basename = os.path.basename(repo)
- pull_from = os.path.join(workspace, other_branch, basename)
- repo_dir = os.path.join(workspace, this_branch, basename)
- app.runcmd(['git', 'pull', pull_from, other_branch], cwd=repo_dir)
+ repo_url = self.resolve_reponame(self.app, repo)
+ repo_path = self._convert_uri_to_path(repo)
+ pull_from = 'file://' + os.path.join(workspace, other_branch,
+ repo_path)
+ repo_dir = os.path.join(workspace, this_branch, repo_path)
+ self.app.runcmd(['git', 'pull', pull_from, other_branch],
+ cwd=repo_dir)
def edit(self, args):
'''Edit a component in a system branch.'''
@@ -336,43 +357,49 @@ class BranchAndMergePlugin(cliapp.Plugin):
raise cliapp.AppException('morph edit must get a repository name '
'and commit ref as argument')
- app = self.app
workspace = self.deduce_workspace()
system_branch = self.deduce_system_branch()
- morphs_dirname = os.path.join(workspace, system_branch, 'morphs')
- if morphs_dirname is None:
- raise morphlib.Error('Can not find morphs directory')
+ # Find out which repository we branched off from.
+ branch_dir = os.path.join(workspace, system_branch)
+ branch_root = self.read_branch_root(branch_dir)
+
+ # Convert it to a local directory in the branch.
+ branch_root_path = self._convert_uri_to_path(branch_root)
+ branch_root_dir = os.path.join(branch_dir, branch_root_path)
- repo = self.resolve_reponame(app, args[0])
+ # Find out which repository to edit.
+ repo, repo_url = args[0], self.resolve_reponame(self.app, args[0])
+ # Find out which ref of the edit repo to check out.
if len(args) == 2:
ref = args[1]
else:
- ref = self.find_edit_ref(app, morphs_dirname, repo)
+ ref = self.find_edit_ref(self.app, branch_root_dir, repo_url)
if ref is None:
raise morphlib.Error('Cannot deduce commit to start edit from')
- new_repo = os.path.join(workspace, system_branch,
- os.path.basename(repo))
- self.clone_to_directory(app, new_repo, args[0], ref)
+ # Clone the repository to be edited.
+ repo_dir = os.path.join(branch_dir, self._convert_uri_to_path(repo))
+ self.clone_to_directory(self.app, repo_dir, repo, ref)
if system_branch == ref:
- app.runcmd(['git', 'checkout', system_branch],
- cwd=new_repo)
+ self.app.runcmd(['git', 'checkout', system_branch],
+ cwd=repo_dir)
else:
- app.runcmd(['git', 'checkout', '-b', system_branch, ref],
- cwd=new_repo)
+ self.app.runcmd(['git', 'checkout', '-b', system_branch, ref],
+ cwd=repo_dir)
- for filename, morph in self.morphs_for_repo(app, morphs_dirname, repo):
+ for filename, morph in \
+ self.morphs_for_repo(self.app, branch_root_dir, repo_url):
changed = False
for spec in morph['sources']:
- spec_repo = self.resolve_reponame(app, spec['repo'])
- if spec_repo == repo and spec['ref'] != system_branch:
- app.status(msg='Replacing ref "%(ref)s" with "%(branch)s"'
- 'in %(filename)s',
- ref=spec['ref'], branch=system_branch,
- filename=filename, chatty=True)
+ spec_repo = self.resolve_reponame(self.app, spec['repo'])
+ if spec_repo == repo_url and spec['ref'] != system_branch:
+ self.app.status(msg='Replacing ref "%(ref)s" with '
+ '"%(branch)s" in %(filename)s',
+ ref=spec['ref'], branch=system_branch,
+ filename=filename, chatty=True)
spec['ref'] = system_branch
changed = True
if changed:
diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
index af1ad6cd..7dc55cc0 100644
--- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
+++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
@@ -9,6 +9,7 @@ d ./newbranch
d ./newbranch/.morph-system-branch
d ./newbranch/morphs
d ./newbranch/morphs/.git
+f ./newbranch/.morph-system-branch/branch-root
f ./newbranch/morphs/hello-stratum.morph
f ./newbranch/morphs/hello-system.morph
f ./newbranch/morphs/this.is.alfred
diff --git a/tests.branching/branch-creates-new-system-branch.stdout b/tests.branching/branch-creates-new-system-branch.stdout
index e22ef30b..c37fb0e4 100644
--- a/tests.branching/branch-creates-new-system-branch.stdout
+++ b/tests.branching/branch-creates-new-system-branch.stdout
@@ -9,6 +9,7 @@ d ./newbranch
d ./newbranch/.morph-system-branch
d ./newbranch/morphs
d ./newbranch/morphs/.git
+f ./newbranch/.morph-system-branch/branch-root
f ./newbranch/morphs/hello-stratum.morph
f ./newbranch/morphs/hello-system.morph
Current branches:
diff --git a/tests.branching/checkout-existing-branch.stdout b/tests.branching/checkout-existing-branch.stdout
index 7ac4a149..1af2900c 100644
--- a/tests.branching/checkout-existing-branch.stdout
+++ b/tests.branching/checkout-existing-branch.stdout
@@ -9,6 +9,7 @@ d ./master
d ./master/.morph-system-branch
d ./master/baserock:morphs
d ./master/baserock:morphs/.git
+f ./master/.morph-system-branch/branch-root
f ./master/baserock:morphs/hello-stratum.morph
f ./master/baserock:morphs/hello-system.morph
Current branches:
diff --git a/tests.branching/checkout-non-aliased-repos.stdout b/tests.branching/checkout-non-aliased-repos.stdout
index 75dcd63d..872d74aa 100644
--- a/tests.branching/checkout-non-aliased-repos.stdout
+++ b/tests.branching/checkout-non-aliased-repos.stdout
@@ -12,6 +12,7 @@ d ./master/TEMP_DIR
d ./master/DATADIR
d ./master/DATADIR/morphs
d ./master/DATADIR/morphs/.git
+f ./master/.morph-system-branch/branch-root
f ./master/DATADIR/morphs/hello-stratum.morph
f ./master/DATADIR/morphs/hello-system.morph
Current branches of repo with suffix:
@@ -30,6 +31,7 @@ d ./master/TEMP_DIR
d ./master/DATADIR
d ./master/DATADIR/morphs
d ./master/DATADIR/morphs/.git
+f ./master/.morph-system-branch/branch-root
f ./master/DATADIR/morphs/hello-stratum.morph
f ./master/DATADIR/morphs/hello-system.morph
Current branches of repo without suffix:
diff --git a/tests.branching/edit-checkouts-existing-chunk.script b/tests.branching/edit-checkouts-existing-chunk.script
index b8480a5b..1c8e66cd 100755
--- a/tests.branching/edit-checkouts-existing-chunk.script
+++ b/tests.branching/edit-checkouts-existing-chunk.script
@@ -33,7 +33,7 @@ echo "Current branches, morphs:"
"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/baserock:morphs" branch
echo "Current branches, hello:"
-"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/hello" branch
+"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/alfred/baserock:hello" branch
echo "Files in hello:"
-ls "$DATADIR/workspace/alfred/hello"
+ls "$DATADIR/workspace/alfred/baserock:hello"
diff --git a/tests.branching/edit-clones-chunk.script b/tests.branching/edit-clones-chunk.script
index 20f62a27..d5e117cb 100755
--- a/tests.branching/edit-clones-chunk.script
+++ b/tests.branching/edit-clones-chunk.script
@@ -38,9 +38,10 @@ echo "Current origin, morphs:"
sed 's,\(TMP/workspace/\.morph/cache/gits/file_\).*_,\1,g'
echo "Current branches, hello:"
-"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/newbranch/hello" branch
+"$SRCDIR/scripts/run-git-in" \
+ "$DATADIR/workspace/newbranch/baserock:hello" branch
echo "Current origin, hello:"
-"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/newbranch/hello" \
+"$SRCDIR/scripts/run-git-in" "$DATADIR/workspace/newbranch/baserock:hello" \
remote show origin | \
sed 's,\(TMP/workspace/\.morph/cache/gits/file_\).*_,\1,g'
diff --git a/tests.branching/edit-uses-ref-from-stratum.script b/tests.branching/edit-uses-ref-from-stratum.script
index ce3e0ccc..f2276f3b 100755
--- a/tests.branching/edit-uses-ref-from-stratum.script
+++ b/tests.branching/edit-uses-ref-from-stratum.script
@@ -29,5 +29,5 @@ cd "$DATADIR/workspace"
cd newbranch/morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello
-cd ../hello
+cd ../baserock:hello
git branch
diff --git a/tests.branching/merge-explicitly-named-repos.script b/tests.branching/merge-explicitly-named-repos.script
index 9052cd31..5a0953a7 100755
--- a/tests.branching/merge-explicitly-named-repos.script
+++ b/tests.branching/merge-explicitly-named-repos.script
@@ -29,7 +29,7 @@ cd "$DATADIR/workspace"
# Make a change to a chunk.
cd newbranch/morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello master
-cd ../hello
+cd ../baserock:hello
touch newfile.txt
git add newfile.txt
git commit -m foo --quiet
@@ -42,7 +42,7 @@ cd otherbranch/morphs
"$SRCDIR/scripts/test-morph" merge newbranch baserock:hello
# Check results.
-cd ../hello
+cd ../baserock:hello
git status --short # make sure all changes are committed
ls newfile.txt # make sure the new file is there
diff --git a/tests.branching/workflow.script b/tests.branching/workflow.script
index 64326e4a..59c7b152 100755
--- a/tests.branching/workflow.script
+++ b/tests.branching/workflow.script
@@ -26,7 +26,7 @@ cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" branch me/readme-fix
cd me/readme-fix/morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello master
-cd ../hello
+cd ../baserock:hello
echo > README yoyoyo
git add README
git commit -m "Fix README, yo!" --quiet
@@ -35,5 +35,5 @@ cd "$DATADIR/workspace"
"$SRCDIR/scripts/test-morph" checkout baserock:morphs master
cd master/baserock:morphs
"$SRCDIR/scripts/test-morph" edit baserock:hello master
-"$SRCDIR/scripts/test-morph" merge me/readme-fix hello
+"$SRCDIR/scripts/test-morph" merge me/readme-fix baserock:hello